Checking hierarchical taxonomy
-
My goal is to display conditional content in an archive page if:
– Post belongs to the parent custom taxonomy and any subcategories of the same parent taxonomy.
Let’s say, custom taxonomy is called custom_taxonomy and it has a category ‘Animals’ ID=01 (Parent)
Subcategories of ‘Animals’ are ‘Beagle’ ID=02 and ‘Retriever’ ID=03.It’s easy with plain post categories and child subcategories.
if (is_category('Animals') || cat_is_ancestor_of('Animals', get_query_var( 'cat' )) { echo 'Successs';
How do I check whether the post belongs to a subcategory of taxonomy parent category ‘Animals’ ID=01?
The first part works fine, but I have like 50 subcategories and I’m certain there should be a better way than listing them one by one.
is_tax('custom_taxonomy', 'Animals') ) ||
- The topic ‘Checking hierarchical taxonomy’ is closed to new replies.