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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.