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;
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.