I have a frontend table form (using Advanced Custom Fields plugin for WordPress) for users to track the number of days each week that they ride their bike to work. Each person has their own row and enters their number for each week. Then I loop through to add up the total number entered for each row and list each person’s name along with their total.
How can I sort this so that the names are listed in order by the highest total ($overalltotal)? Here is my code, which correctly lists the names along with their totals, but it is unsorted:
$rows = get_sub_field('ride_tracker');
foreach( $rows as $row )
{
$overalltotal = intval($row['week_1'] + $row['week_2'] + $row['week_3'] + $row['week_4']);
echo $row['name'] . ' : ' . $overalltotal . '<br />' ;
}
I’ve read about array_multisort and usort, but I can’t figure out how to get these to work with a variable that’s calculated during the loop.
Thank you for your help!
ACF is an awesome plugin. I use it for everything.
I see you are using sub_fields so I assume you are using a repeater.
ACF uses this format
array_multisort( $column_id, SORT_ASC, $repeater );
This page may help you out a lot, shows how to sort fields in ACF.