Last active
May 21, 2025 02:00
-
-
Save saifsultanc/32f1fa38b4d7082f7a60925b98a71afa to your computer and use it in GitHub Desktop.
gpeb_queryer_entries-multi-field-sorting.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gpeb_queryer_entries', function( $entries, $gf_queryer ) { | |
// Update the form ID to match your form. | |
if ( $gf_queryer->form_id != 933 ) { | |
return $entries; | |
} | |
// Update the field IDs to match your form. | |
$primary_sorting_field_id = '1.6'; | |
$secondary_sorting_field_id = '1.3'; | |
$sorting_direction = 'ASC'; // 'ASC' or 'DESC' | |
usort( $entries, function( $a, $b ) use ( | |
$primary_sorting_field_id, | |
$secondary_sorting_field_id, | |
$sorting_direction | |
) { | |
$a_primary = isset( $a[ $primary_sorting_field_id ] ) ? $a[ $primary_sorting_field_id ] : ''; | |
$b_primary = isset( $b[ $primary_sorting_field_id ] ) ? $b[ $primary_sorting_field_id ] : ''; | |
$cmp = strcasecmp( $a_primary, $b_primary ); | |
if ( $cmp === 0 ) { | |
$a_secondary = isset( $a[ $secondary_sorting_field_id ] ) ? $a[ $secondary_sorting_field_id ] : ''; | |
$b_secondary = isset( $b[ $secondary_sorting_field_id ] ) ? $b[ $secondary_sorting_field_id ] : ''; | |
$cmp = strcasecmp( $a_secondary, $b_secondary ); | |
} | |
return ( $sorting_direction === 'DESC' ) ? -$cmp : $cmp; | |
}); | |
return $entries; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment