Support

Account

Home Forums Add-ons Repeater Field Combine 2 repeater rows with same values Reply To: Combine 2 repeater rows with same values

  • Thanks, what I mean is to combine two arrays (captured from two different acf repeater rows), so that they combine and can be sorted alphabetically.
    Each repeater has these fields
    $this_array = repeater fields $arg1 and $arg2
    $that_array = repeater fields $arg1 and $arg2
    $result = array_merge_recursive($ar1, $ar2);
    sort($result);

    This sample does note combine them and display them alphabetically:

    
    <?php
    $this_array                           = get_field('this_array');
    $that_array                           = get_field('that_array');
    ?>
    <ul class="panel">
      <?php    if( have_rows('this_array') ): ?>
          <?php  while ( have_rows('this_array') ) : the_row();
              $arg1                    = get_sub_field('arg1');
              $arg2                      = get_sub_field('arg2');
          ?>
              <li><?php the_sub_field('arg1') ?><span>
                  <?php the_sub_field('arg2') ?></span></li>
          <?php endwhile; ?>
          <?php  else : // no rows found
      endif; ?>
      <?php    if( have_rows('that_array') ): ?>
            <?php  while ( have_rows('that_array') ) : the_row();
                $arg1                    = get_sub_field('arg1');
                $arg2                      = get_sub_field('arg2');
              ?>
                      <li><?php the_sub_field('arg1') ?><span>
                          <?php the_sub_field('arg2') ?>
                          </span></li>
            <?php endwhile; ?>
            <?php  else : // no rows found
      endif; ?>
    </ul>