get taxonomy name of current post

Question

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 ?

in progress 0
, , , andy 10 years 2011-07-13T02:16:30-05:00 0 Answer 77 views 0

Answer ( 1 )

    0
    2021-08-06T03:10:46-05:00

    This is very good code for get taxonomy title in detail page or single page in custom post type in WordPress,

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

Leave an answer

Browse
Browse