Ready to get started?Download WordPress


List Taxonomy terms seperated by commas (2 posts)

  1. Phil
    Posted 1 year ago #


    I have some custom fields that display data front-end and are called via:

         $terms = get_the_terms( $post->ID, 'sector' );
         foreach ( $terms as $term ) {
         echo $term->name;
     } ?>

    However, when multiple entries have been selected, the terms are displayed without any spaces, commas or other seperators (eg, MyTerm1MyTerm2... etc). I've tried a few implode methods but I either get blank placeholder or it breaks the page.

    I am in the loop by the way.

    Any ideas?

  2. Phil
    Posted 1 year ago #

    Anyone, any ideas?

    I've also tried this:

    $terms = get_the_terms( $post->ID, 'sector' );
    $newTerms =  Array();
    foreach ($terms as $term) :
    $newTerms[] = $term->name;
    echo implode(', ', $newTerms);

Topic Closed

This topic has been closed to new replies.

About this Topic