WordPress.org

Support

Support » How-To and Troubleshooting » List Taxonomy terms seperated by commas

List Taxonomy terms seperated by commas

  • Phil
    Member

    @owendevelopment

    Hi,

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

    <?php
         $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?

Viewing 1 replies (of 1 total)
  • Phil
    Member

    @owendevelopment

    Anyone, any ideas?

    I’ve also tried this:

    <?php
    $terms = get_the_terms( $post->ID, 'sector' );
    $newTerms =  Array();
    foreach ($terms as $term) :
    $newTerms[] = $term->name;
    endforeach;
    
    echo implode(', ', $newTerms);
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘List Taxonomy terms seperated by commas’ is closed to new replies.