how can i test if a wordpress taxonomy/term page is a child of another term? For instance, if i have a taxonomy for “portfolio-categories” which is hierarchical. my top level terms are “digital” and “print”. under print, i have “television”.. and a few others. if i am on the “television” archive, is_tax() is true as is is_tax(‘television’) but not is_tax(‘print’). basically i’d like ‘television’ and its siblings to behave one way while the children of “digital” behave another.
is this possible or would this be best served by separate taxonomies?
In that page say archive-portfolio-categories.php or just archive.php .. I believe you can use the global variable $term to determine if you are on a child page. E.g.:
This should work if you only have the 2 top-level items with slugs ‘print’ and ‘digital’. This code will also work for deeper taxonomy trees.
Note that I have changed to code from my own working code. There might be small typo’s. So please check and don’t blindly copy paste this.
The global $term not appear.
But you can use the global $wp_query, you can test in taxonomy-{tax}.php :
We see the $wp_query->queried_object->parent, and :