Support » Fixing WordPress » Taxonomy term descriptions in below post content

  • Resolved jvinch

    (@jvinch)


    Folks,

    I am trying to show a term description at the bottom of a post. The term is part of a custom taxonomy.

    For instance, a post is assigned to the term Apples. In single.php, I’m listing the_content, to be followed by the description of the term this specific post is assigned to.

    I’m using

    <?php echo term_description( '', get_query_var( 'taxonomy' ) ); ?>

    for taxonomy.php – but this obviously won’t work for single.php.

    What snippet could I use to:

    Display the term_description for term to which this post is assigned? I know how to get the term list with

    <?php echo get_the_term_list( $post->ID, 'taxonomy-name', '', ', ', '' ); ?>

    but I’m drawing a blank for the description.

    Thanks in advance for your help

    John

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thought I’d give this one a bump. Anyone?

    Use this

    $taxonomy='your_taxonomy_goes_here';
    $terms=get_the_terms($post->ID,$taxonomy);
    echo "<pre>"; print_r($terms); echo "</pre>";

    Michael – that’s getting me somewhere, but not where I need to be yet.

    Here’s what it prints:

    `Array
    (
    [774] => stdClass Object
    (
    [term_id] => 774
    [name] => The Name
    [slug] => the-name
    [term_group] => 0
    [term_taxonomy_id] => 826
    [taxonomy] => the taxonomy
    [description] => the description the description the description etc
    [parent] => 0
    [count] => 16
    [object_id] => 1461
    )

    )

    We’re probably extremely close, I just don’t know how to adjust the above to just print the term description.

    $terms = get_the_terms( $post->ID , 'taxonomy-name_here' );
    echo $terms->description;

    t31os_ – that does nothing for me. No result.

    Just to make sure we’re all on the same page – I am trying to print a term description at the top or bottom of single.php, not on taxonomy pages.

    $terms = get_the_terms( $post->ID , 'taxonomy_Name' );
    if($terms) {
    	foreach( $terms as $term ) {
    		echo $term->description.'<br />';
    	}
    }

    Just need to loop over results… 🙂

    Bingo – spelling of description threw me for a loop in the last snippet, but works like a champ now.

    For anyone else –

    <?php $terms = get_the_terms( $post->ID , 'taxonomy-name' );
    if($terms) {
    	foreach( $terms as $term ) {
    		echo $term->description.'<br />';
    	}
    }
    ?>

    Thanks much, Michael and t31os_!

    I have the following code:

    <?php $terms = get_the_terms( $post->ID , 'people' );
    	if($terms) {
    		foreach( $terms as $term ) {
    		echo '<div class="authorbio">'.$term->description.'<br /></div>';
    	}
    }
    ?>

    I only have descriptions on certain custom tags. I don’t want to display the “authorbio” divs when the description is missing. How do I do it?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Taxonomy term descriptions in below post content’ is closed to new replies.