get_terms return errors

As i was mentioning before, it’s a case of your term fetching occuring before the taxonomy has been registered. The init action occurs after the theme’s functions file has been included, so if you’re looking for terms directly in the functions file, you’re doing so before they’ve actually been registered. Here’s a portion of the … Read more

get taxonomy terms for parent and child

You should have two foreach loops. One for getting parent taxonomy terms, and second for getting child taxonomy terms. In the second foreach you need to specify the parent taxonomy term ID which is $parent_term->term_id from the first foreach loop. foreach( get_terms( ‘products-category’, array( ‘hide_empty’ => false, ‘parent’ => 0 ) ) as $parent_term ) … Read more

Retrieve a specific field from taxonomy term through advanced custom fields [closed]

To retrieve a field from ACF for a term (instead of, for example, a post), you should use the taxonomy name, followed by an underscore, followed by the term ID instead of the post ID when calling the_field or get_field. Assuming you want to retrieve the field image_toc for the taxonomy mytax and term ID … Read more

Update term count using a callback function

I think I’ve worked this out. First of all, you need to define your taxonomy. I’m pulling this code directly from the codex; however, I’ve added one parameter update_count_callback. I’ve set this to the cleverly titled my_update_count_callback. This just specifies that when a post of type post (this will be whatever CPTs you associate the … Read more

get_post_terms not working as expected

I misunderstood what you were trying to do before. I thought you wanted to list the terms associated with one particular post – the one you are on. Whoops! Try this instead: $terms = get_terms(‘fruit_category’); if(!empty($terms)){ echo “<ul>”; foreach ( $terms as $term ) { echo ‘<li><a href=”‘.get_term_link($term->slug, ‘fruit_categories’).'”>’. $term->name . “</a></li>”; } echo “</ul>”; … Read more