Get the list of the terms/categories related to a specific custom post
-
Hallo, i’m tring to get the list of terms/categories related to a specific custom post but i have odd results. The list of terms sometime include all the real terms related to a specific post, sometime the list doesn’t include all the terms.
This is the code, i’m using this in get_footer hook:
//getting all the taxonomies related to this specific post $taxonomies = get_object_taxonomies( $current_post_type ); foreach ($taxonomies as $taxonomy) { //for each taxonomy i get the terms related to this post $terms = get_the_terms( get_the_ID(), $taxonomy ); if( $terms != false ){ foreach ($terms as $term) { //collecting the term name $result[] = $term->term_name; } } }
This code seems to work but the reality is that i don’t get always all the terms.
Which method are you using to complete the same task?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Get the list of the terms/categories related to a specific custom post’ is closed to new replies.