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 have a custom taxonomy called "Artists" which has the taxonomy singular name set to "Artist".

If a post only has 1 artist I would like the label to be "Artist" instead of "Artists".

How could I achieve this? My current code is below. Thanks!

        $taxo_text = "";  
        $artists = get_the_term_list( $post->ID, 'artists', "<div class='grid_2 details'>
     <ul class='credits'> <li class='smallunderline'>Artists</li><li> ", '</li><li>', '</li></ul></div>' );  

        if ( '' != $artists ) {  
            $taxo_text .= $artists;  

        if ( '' != $taxo_text ) {  

        echo $taxo_text;  

        } // endif  

share|improve this question

get_the_terms() returns an array of the terms, and is used by get_the_term_list() to build the links. You can query it and count the number of returned terms. Since the result is cached, it won't query the database again.

$artists = get_the_terms( $post->ID, 'artists' );
if ( $artists ) {
    $artistsLabel = ( 1 == count( $artists ) ? 'Artist' : 'Artists' );
    $taxo_text .= get_the_term_list( $post->ID, 'artists', "<div class='grid_2 details'>
 <ul class='credits'> <li class='smallunderline'>{$artistsLabel}</li><li> ", '</li><li>', '</li></ul></div>' ); 
share|improve this answer
Shouldn't this already be covered if the taxonomy is registered with all the appropriate labels, namingly a singular and plural label? – t31os Dec 3 '10 at 11:53
@t31os: You would expect so, but get_the_term_list() is not very advanced and appends just the $before parameter, it makes no attempt to create a sensible default value. – Jan Fabry Dec 3 '10 at 13:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.