Home Forums Add-ons Repeater Field Sorting repeater field from high to low


Sorting repeater field from high to low

  • Hi

    I had created a repeater field in ACF Pro, and I would like a sub_field named ‘id’ to be sorted from high to low.

    That means, the rows with the highest ID must appear at the top.

    I have written the code below and it works perfectly. The problem is just that it sorts the IDs from low to high.

    How can I change it?

    <?php // Get repeater value
              $repeater = get_field('repeater');
              // Obtain list of columns
              foreach ($repeater as $key => $row) {
                  $the_name[$key] = $row['id'];
              // Sort the data by name column, ascending
              array_multisort($the_name, SORT_ASC, $repeater); ?>
          <?php if($repeater): ?>
                    <?php foreach( $repeater as $row ) { // Display newly orded columns ?>
                          <li><?php echo $row['id']; ?></li>
                    <?php } ?>
          <?php endif;?>
Viewing 1 post (of 1 total)

The topic ‘Sorting repeater field from high to low’ is closed to new replies.