WordPress.org

Ready to get started?Download WordPress

Forums

List Taxonomy terms seperated by commas (2 posts)

  1. Phil
    Member
    Posted 1 year ago #

    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?

  2. Phil
    Member
    Posted 1 year ago #

    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);
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic