Support

Account

Forum Replies Created

  • Sorry, I will try to illustrate below:

    pigeons_and_doves is an acf repeater that collects one set of data with two keys
    other_pigeons_and_doves is an acf repeater that collects one set of data with two keys
    when combining them into the array with this sort method it is listing them as

    pigeons_and_doves key values first
    A some name in list (pigeons_and_doves)
    Z some name in list (pigeons_and_doves)
    X some name in list (pigeons_and_doves)

    other_pigeons_and_doves key values first
    F some name in list (other_pigeons_and_doves)
    B some name in list (other_pigeons_and_doves)
    D some name in list (other_pigeons_and_doves)

    so when they are run out in the loop that you advised with the usort they are displaying like this: (pigeons_and_doves all at top of list and other_pigeons_and_doves all at bottom of the list)

    A some name in list (pigeons_and_doves)
    X some name in list (pigeons_and_doves)
    Z some name in list (pigeons_and_doves)
    B some name in list (other_pigeons_and_doves)
    D some name in list (other_pigeons_and_doves)
    F some name in list (other_pigeons_and_doves)

    INSTEAD OF LIKE THIS
    A some name in list (pigeons_and_doves)
    B some name in list (other_pigeons_and_doves)
    D some name in list (other_pigeons_and_doves)
    F some name in list (other_pigeons_and_doves)
    X some name in list (pigeons_and_doves)
    Z some name in list (pigeons_and_doves)

  • Thanks, but that is still sorting the list into the first and second acf rows.

  • They sort in their own original rows but the combined array is not merging.

  • Thank you, I managed to get that but they are still not merging alphabetically.
    Here is my code:
    `<!– ********************************** PIGEONS AND DOVES –>
    <?php if( ($pigeons_and_doves || $other_pigeons_and_doves) ): //<!– THIS WILL NOT HIDE when empty –>

    // Add all rows of $this_array to the array of all rows.
    if ( have_rows( ‘pigeons_and_doves’ ) ) :
    while ( have_rows( ‘pigeons_and_doves’ ) ) : the_row();
    $final_array[] = [
    ‘bird_name’ => get_sub_field( ‘pigeon_and_dove_species’ ) ,
    ‘price’ => get_sub_field( ‘bird_price’ ) ,
    ];
    endwhile;
    endif;

    // Add all rows of $that_array to the array of all rows.
    if ( have_rows( ‘other_pigeons_and_doves’ ) ) :
    while ( have_rows( ‘other_pigeons_and_doves’ ) ) : the_row();
    $final_array[] = [
    ‘bird_name’ => get_sub_field( ‘other_pigeon_and_dove_species’ ) ,
    ‘price’ => get_sub_field( ‘other_bird_price’ ) ,
    ];
    endwhile;
    endif;
    sort($final_array);
    ?>
    <div class=”animal-listing-col”>
    <table>
    <tr>
    <th>Pigeons and Doves</th>
    <th>PRICE</th>
    </tr>
    <?php foreach($final_array as $row) {
    ?>
    <tr>
    <td><?php echo $row[‘bird_name’]; ?> </td>
    <!– CURRENCY –> <td><?php if( get_field(‘currency’) && $row[‘price’] && is_numeric($row[‘bird_price’])): the_field(‘currency’); endif; ?>
    <?php echo $row[‘price’]; ?>
    </td>
    </tr>
    <?php } ?>
    </table>
    </div> <!– end pigeons loop –>
    <?php endif; ?>
    <!– ********************************** end pigeons and doves –>

  • 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>
    
Viewing 5 posts - 1 through 5 (of 5 total)