I need to add a div around every pair of ACF repeater fields entered.
I have this snippet of code which does the job for every three fields. Each time I change the number it makes the next div ID a child of the previous.
Any suggestions would be great! Thanks

// check if the repeater field has rows of data
if( have_rows('services') ):
  // loop through the rows of data

  // add a counter
  $count = 0;
  $group = 0;

  while ( have_rows('services') ) : the_row(); 
    // vars
    $teacher_bio = get_sub_field('service_title');
    $teacher_name = get_sub_field('service_information');
    $teacher_image = get_sub_field('icon');
    if ($count % 3 == 0) {
      $group++;
      ?>
        <div id="services-<?php echo $group; ?>" class="cf group-<?php echo $group; ?>">
      <?php 
    }
    ?>
    <div class="service">
      <img src="<?php the_sub_field('icon'); ?>" />
      <p><?php echo $teacher_name; ?></p>
      <?php echo $teacher_bio; ?>
    </div><!-- .teacher -->
    <?php 
      if ($count % 3 == 2) {
        ?>
          </div><!-- #services -->
        <?php 
      }
      $count++;
    endwhile;
else :
  // no rows found
endif;

Read more here: Adding div around every 2 repeater fields ACF


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: