Home › Forums › Add-ons › Repeater Field › Remove Trailing Comma in Repeater Field Output › Reply To: Remove Trailing Comma in Repeater Field Output
You can use the get_row_index() to get the current row index and then only show the comma if it’s not the first row like this:
if( have_rows('services') ):
while ( have_rows('services') ) : the_row();
$service_name = get_sub_field('service_name');
if( get_row_index() != 1 ){ echo ', ' }
echo $service_name;
endwhile;
endif;
I hope this helps 🙂
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.