Get post terms for multiple posts at once?

That would be wp_get_object_terms. You’d need an array of post id’s as the input, together with the taxonomy you want to retrieve the terms for (let’s say: books). This should work (untested): $my_query = new wp_query ($args); $my_posts = $my_query->posts; $my_post_ids = wp_list_pluck ($my_posts, ‘ID’); $my_terms = wp_get_object_terms ($my_post_ids, ‘books’);

Get a list of Terms for a specific category

The following code will do it. Please change the ‘filter’ text in the below code to whatever filters taxonomy name you have set. if(is_category() ){ $thiscat = get_queried_object_id(); $filter_tax = array(); $args = array( ‘category’ => $thiscat ); $lastposts = get_posts( $args ); foreach ( $lastposts as $post ){ setup_postdata( $post ); $terms = get_the_terms( … Read more

get_terms parent for current product only

get_terms relates to getting all the terms of a taxonomy. get_the_terms grabs all the terms related to the post. The problem is that it sounds like you only want to return those terms which are parent categories, not the children, and get_the_terms does not pass an arguments array. $terms = get_the_terms( get_the_ID(), ‘product_cat’ ); foreach … Read more

How to add class on term link?

I think you should use a custom loop: <?php $terms = get_the_terms( $post->ID, ‘product_tag’ ); if ($terms && ! is_wp_error($terms)): ?> <?php foreach($terms as $term): ?> <a href=”https://wordpress.stackexchange.com/questions/130622/<?php echo get_term_link( $term->slug,”product_tag’); ?>” rel=”tag” class=”<?php echo $term->slug; ?>”><?php echo $term->name; ?></a> <?php endforeach; ?> <?php endif; ?>

Checking if a Page has an Associated Term?

Hi @NetConstructor: First thing, assuming your logic worked you can use the ternary operator to simplify your example: <li id=”kids-<?php echo is_term(‘Kids’,’age_groups’) ? ‘on’ : ‘off’; ?>”>Kids Programs</li> The issue seems to be that is_term() is used to check if a term exists, not if it is associated with a particular post. I think what … Read more

Creating a function that receives the taxonomy terms that have been changed in a custom post type

After WordPress has updated a posts’ taxonomy terms it triggers the action: set_object_terms (see source) which passes 6 variables: Object ID Terms that were assigned to the post (or added depending on 5) (could be their slug or term ID). Taxonomy-term IDs of above (not term IDs) The taxonomy Append. If true – terms in … Read more

Advanced custom fields – taxonomy terms images [closed]

OK had a go at this myself, I didn’t realise ACF was able to add fields to taxonomies which is really handy so I wanted to figure it out too. <?php $libargs=array( ‘hide_empty’ => 0, ‘parent’ => 0, ‘taxonomy’ => ‘library_categories’); $libcats=get_categories($libargs); foreach($libcats as $lc){ $termlink = get_term_link( $lc->slug, ‘library_categories’ ); ?> <a class=”single-library-cat” href=”https://wordpress.stackexchange.com/questions/71287/<?php … Read more