How to sort by multiple fields in GFAPI::get_entries()

You can’t. It’s not possible in Gravity Forms 2.3. Do this instead.

The third parameter to get_entries() is not designed to accept more than one sort field. Use array_multisort() to sort the array output of get_entries() like this:

$entries = GFAPI::get_entries( 22, '', null ); //form #22 Tournament team registration
$sort = array();
foreach( $entries as $k => $v ) {
	//Build an array full of the fields we want to sort $entries by
	$sort['is_approved'][$k] = $v['is_approved'];
	$sort['16'][$k] = $v['16']; //field #16 Company name
//Sort $entries by is_approved descending, then field 16 ascending
array_multisort( $sort['is_approved'], SORT_DESC, $sort['16'], SORT_ASC, $entries );

Leave a comment

Your email address will not be published. Required fields are marked *