Query all posts of a custom taxonomy term

I believe your issue is with understanding the nature of posts’ hierarchy vs pages’ hierarchy. A page is a type of “post”. It can have hierarchical structure. Posts, by default, do not have hierarchy. So, you would not be able to get post-parents without their children, because the system does not recognize a hierarchy. This … Read more

get_terms adds slaces to the resualt

What you’d need to do is double-escape, so change echo ‘\” . $term->name . ‘\’, ‘; to echo ‘\\\” . $term->name . ‘\\\’, ‘; …but, you’d be much better off just using different encapsulators: <select class=”w-100″ name=”mf_term”> <option value=” <?php $terms = get_terms( ‘call-type’ ); if ( ! empty( $terms ) && ! is_wp_error( $terms … Read more

Why “Warning: Invalid argument supplied for foreach()”

According to the documentation, get_the_terms() returns an array of WP_Term objects, or a boolean false value, or a WP_Error object. The last two won’t work with foreach(). You could update your code to check for these conditions: $orgs_in_post = get_the_terms($post[‘ID’], ‘company’); if ( is_array( $orgs_in_post ) ) { foreach ($orgs_in_post as $org_single) { array_push($recent_companies, $org_single->term_id); … Read more

WordPress Related Post by tags in Single.php

The code shown isn’t working as wished, what is wrong? you’re using only the first tag : $first_tag = $tags[0]->term_id; to grab posts from all tags you have to iterate the whole array until a max of 5. The code below ( untested) grabs a max of 25 posts theoretically using up to 5 tags..BUT … Read more

Display the description of taxonomy terms

get_terms() returns an array of WP_Term objects. To get the description, with the usual filters applied, you can pass this object to term_description(): $terms = get_terms( array( ‘taxonomy’ => ‘organizer’, ‘hide_empty’ => false, ) ); if ( ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { echo term_description( $term ); } … Read more

Set post categories to include parents when setting child category

This will check to see if there is a hierarchy and set all parent categories as checked. This function assumes that if there’s multiple categories already set, then don’t do the function, since the categories would be correct if multiples are set. function set_product_parent_categories( $post_id ) { $category = wp_get_post_terms( $post_id, ‘product_cat’ ); // If … Read more