Support

Account

Home Forums Add-ons Repeater Field Remove Trailing Comma in Repeater Field Output Reply To: Remove Trailing Comma in Repeater Field Output

  • Hi @juanmtorrijos

    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 🙂