WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wondering how can I write a conditional tag that affects a custom taxonomy slug and its children?

Found this in Wordpress Codex:

is_tax( 'flavor', 'mild') 

When the archive page for the flavor taxonomy with the slug of 'mild' is being displayed.

However with this code only 'mild' slug archive page is affected and not it's children taxonomy terms.


share|improve this question
up vote 2 down vote accepted

I have a handy little function that i based on post_is_in_descendant_category function it expends the is_tax to check if its the term or any of his children

function is_or_descendant_tax( $terms,$taxonomy){
    if (is_tax($taxonomy, $terms)){
            return true;
    foreach ( (array) $terms as $term ) {
        // get_term_children() accepts integer ID only
        $descendants = get_term_children( (int) $term, $taxonomy);
        if ( $descendants && is_tax($taxonomy, $descendants) )
            return true;
    return false;

and you use it just the same so instead of:

is_tax('flavor', 'mild');

you put:

is_or_descendant_tax(get_term_by( 'name', 'mild', 'flavor' ), 'flavor');

or if you are using term id instead of name then:

is_or_descendant_tax(12, 'flavor');

and you are set.

share|improve this answer
thank you it worked great! :D – b0nd Mar 24 '11 at 1:41
That was really helpfull, thanks a lot :) – Rise Apr 20 '11 at 21:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.