3

In a Wordpress blog, I'd like to put the term description of a specific custom taxonomy in the footer of each article.

Is this possible? I've tried

<?php term_description( $term_id, $taxonomy ) ?>

but no luck. Unless I'm using it incorrectly? When used, nothing shows up.

2
  • OK, and what's in your $term_id, $taxonomy?
    – Olexandr Skrypnyk
    Commented Oct 10, 2011 at 16:06
  • Well, $term_id is different from post to post. The $taxonomy would be consistent, in this case it's projects.
    – Scott Chandler
    Commented Oct 10, 2011 at 16:11

1 Answer 1

6

sounds like a silly question but are you echo'ing it out?

<?php echo term_description($term_id, $taxonomy); ?>

otherwise you'll need to get the current post's terms (where my_term is your custom taxonomy):

$terms = wp_get_post_terms( $post->ID, 'my_term' ) 

then get the description for the first term in ther array:

echo term_description($terms[0]->term_id, 'my_term');

I've not tested this but it should put you in the right direction.

So here's the full code below (should go in the single.php or loop.php or wherever your single post is created)...paste it inside the loop:

    <?php $my_taxonomy = 'projects'; // set this to whatever your custom taxonomy is called

$terms = wp_get_post_terms( $post->ID, $my_taxonomy ); // this gets all the terms attached to the post for your custom taxonomy

echo term_description($terms[0]->term_id, $my_taxonomy); // this displays the description for the first term in the $terms array ?>

Hope it helps,

Dave

7
  • Hmm, okay. Thank you. But how exactly do I put this all together? I'm still pretty new to PHP.
    – Scott Chandler
    Commented Oct 10, 2011 at 20:12
  • 1
    ok well assuming you are familiar with the WordPress loop all you need to do is place the above code wherever you want inside the loop (ive updated the answer) Commented Oct 10, 2011 at 21:35
  • 1
    also edited as I posted the wrong function, and I've also added 'projects' as the taxonomy :-) Commented Oct 10, 2011 at 21:50
  • Thanks, but it's still not working for me. Here's what I have in the single.php file: <?php get_header(); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $my_taxonomy = 'projects'; $terms = wp_get_post_terms( $post->ID, $my_taxonomy ) ?> <article <?php post_class() ?> id="post-<?php the_ID(); ?>"> <h1><a href="<?php the_permalink() ?>"> <?php the_title(); ?></a></h1> <div class="entry"> <?php the_content(); ?> </div> <?php echo term_description($terms[0]->term_id, $my_taxonomy); ?> </article><?php endwhile; ?> <?php get_footer(); ?>
    – Scott Chandler
    Commented Oct 10, 2011 at 22:32
  • 1
    Hi Scott, no worries. I've tried the above code and its works spot on for me? Could you show me how you're creating the custom taxonomy? Think that might be the issue. You also need an endif; just before you call get_footer. I missed a ; out the code above so ive updated it again. Commented Oct 11, 2011 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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