Support

Account

Home Forums ACF PRO Separate Custom Taxonomy By Comma Reply To: Separate Custom Taxonomy By Comma

  • There are several ways to do this, one involves using a counter so that you don’t add a comma after the last one.

    
    <?php 
      $terms = get_field('location_type');
      if( $terms ):
        $total = count($terms)
        $count = 1;
        foreach( $terms as $term ):
          ?>
            <a href="<?php 
              echo get_term_link( $term ); ?>"><?php 
              echo $term->name; ?></a>
          <?php 
          if ($count < $total) {
            echo ', ';
          }
          $count++;
        endforeach;
      endif; 
    ?>