Support

Account

Home Forums ACF PRO Put a comma after the last repeater field value

Solving

Put a comma after the last repeater field value

  • Hi, I’ve the following code

    <?php if(have_rows('ore')):?>
    
    		<?php while( have_rows('ore')): the_row();
    
     			    $start = get_sub_field('start');
    					$end = get_sub_field('end');
    		?>
    
             <?php if( get_row_index() != 1 ){ echo '/'; }?>
           
    				  <?php echo $start;?> – <?php echo $end;?>	
    	
    	<?php endwhile;?>
    <?php endif;?>

    Which outputs the two fields (start & end) in this form: “12.00 – 13.00”. In case there are more they’ll be displayed like this 12.00 – 13.00 / 15.40 – 16.00 and so on.

    How can I put a comma after the last field?

    Thanks
    David

  • put echo ', ' between the end of the while and end of the if

  • Hi John, thank you for your answer, doing so I had a space before the comma.

    I did some further research and found out that was because I was switching in and out PHP, that was causing the whitespace to be echoed out.

    thank you anyway
    David

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.