Words and code and rock and roll

Displaying custom WordPress taxonomy terms with or without links

Published 2012-1-22 (Modified 2012-1-23)

WordPress lets you create custom taxonomy terms, a feature that makes WordPress a very good CMS. If you want to display these terms (on a specific post), there are more than one way to do this.

If you want to list the terms associated with a specific post with a link to a term archive, you can use the get_the_term_list() function. This displays the terms (including a term link). To run through the terms, use code similar to this (from the codex):

<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ' ', '' ); ?>

But if you want to display the terms without the links, you can use code similar to this, using wp_get_object_terms():

$people_terms = wp_get_object_terms($post->ID, 'people');
  if(!is_wp_error( $people_terms )){
    echo '<ul>';
      foreach($people_terms as $term){
      echo '<li>'.$term->name.'</li>';
    echo '</ul>';

To display all the terms, regardless of the specific post, you can use the get_terms() function. Code similar to this lists the terms in a unordered list

$terms = get_terms("people");
 $count = count($terms);
 if ( $count > 0 ){
     echo "<ul>";
     foreach ( $terms as $term ) {
       echo "<li>" . $term->name . "</li>";
     echo "</ul>";