• Resolved kurdt_the_goat

    (@kurdt_the_goat)


    Hi,

    I have a site with many custom taxonomies.
    On the homepage, i just want to show 3 of the terms for a post instead of all of them, to avoid cluttering the listing.

    I have this code for getting terms from all of my taxonomies displaying:

    echo get_the_term_list( $post->ID, array(‘franchise’, ‘publisher’, ‘developer’, ‘platform’), ‘All Terms: ‘, ‘, ‘, ” );

    Is there a way to limit the output to just 3 terms?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Timothy Jacobs

    (@timothyblynjacobs)

    Please use the code button in future posts.

    $terms = get_the_term_list( $post->ID, array('franchise', 'publisher', 'developer', 'platform'), 'All Terms: ', ',' );
    $max_terms = 3;
    $terms_array = explode( ',', $terms, $max_terms + 1 );
    array_pop( $terms_array );
    $terms = implode( ',', $terms_array );
    echo $terms;
    Thread Starter kurdt_the_goat

    (@kurdt_the_goat)

    Apologies for not using code button, and appreciate your answer which worked perfectly, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limit number of terms output by get_the_term_list’ is closed to new replies.