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 would like to display just the first term from a custom post type custom taxonomy.

Inside my loop I've been displaying all the terms using:

<?php echo get_the_term_list( $post->ID, 'traits', 'Physical Traits:', ''); ?>

but I would like to only display the first term.


share|improve this question
up vote 2 down vote accepted

A little bit more involved but:


function get_single_term($post_id, $taxonomy) 
    $terms = wp_get_object_terms($post_id, $taxonomy);
        return '<a href="'.get_term_link($terms[0]->slug, $taxonomy).'">'.$terms[0]->name.'</a>';   

echo get_single_term(5, 'category');
share|improve this answer

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.