Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

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.