0

I am using this code to display description of a taxonomy.

<?php $my_taxonomy = 'institute'; $terms = wp_get_post_terms( $post->ID, $my_taxonomy ); echo term_description($terms[0]->term_id, $my_taxonomy); ?>

What to do if I want to show description of sub or even sub-taxonomy?

1
  • Btw, does term_description work with custom taxonomies? The codex doesn't say so and I haven't tried it yet. – Rutwick Gangurde Dec 21 '11 at 6:56
0

Term description works only with term id and the taxonomy name, so if you want to get the sub term's description, you should first get all the children of a term(and their children, if its another level deep) and loop over their ids with a single term_description call per id.

<?php 
    $my_taxonomy = 'institute';
    $terms = wp_get_post_terms( $post->ID, $my_taxonomy );
    echo term_description($terms[0]->term_id, $my_taxonomy);

    //Assuming you have only 1 parent term, if multiple then loop over the $terms array
    $term_children = get_term_children( $terms[0]->term_id, $my_taxonomy );

    foreach($term_children as $term_child)
    {
        echo term_description($term_child->term_id, $my_taxonomy).'<br />';
    }
?>

This should give you an idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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