Hierarchical taxonomy of custom post type ‘projects’ > ‘projects_category’.

Two example ‘projects_category’ hierarchies would be:

Big Corporates > 1st Company Name > A Post Title

Small Business > 2nd Company Name > Another Post Title

I can get ‘1st Company Name’ with the following:

<?php $terms = get_the_terms($post->ID, 'projects_category');foreach($terms as $term){echo $term->name;} ?>

How can I display ‘Big Corporates’ or ‘Small Business’ as appropriate in single.php ?

4 Answers
4

get_ancestors() should do what you need:

So, you should do something like this:

$ancestors = get_ancestors($term_id, 'projects_category)

Leave a Reply

Your email address will not be published. Required fields are marked *