Support

Account

Home Forums Add-ons Repeater Field Repeater Field – control sort order?

Unread

Repeater Field – control sort order?

  • I am using a repeater field (called values) with subfields of “name”,”week_1″ and “week_2”. I found this code to run a foreach loop that output the results in order by a field ID (in this example, I’m using “name”):

    
    $rows = get_field('values');
    
    if($rows)
    
    foreach( $rows as $key => $row )
    	{
        $column_id[ $key ] = $row['name'];  
    	}
    
    array_multisort( $column_id, SORT_ASC, $rows );
    
    foreach( $rows as $row )
    {
    
    	 $rowtotal = intval($row['week_1'] + $row['week_2']) ;   
    	 
    	 echo $row['name'] . ' : ' . $rowtotal . '<br>' ;
         
    }
    

    This correctly sorts by Name. However, I’d like to modify this so that it’s not being sorted in order by a field ID, but instead is being sorted by $rowtotal (the sum of the “week_1” + “week_2”).

    How can I do this?

Viewing 1 post (of 1 total)

The topic ‘Repeater Field – control sort order?’ is closed to new replies.