|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Gravity Perks // Entry Blocks // Multi Field Sorting |
| 4 | + * https://gravitywiz.com/documentation/gravity-forms-entry-blocks/ |
| 5 | + * |
| 6 | + * Use confirmation message from Form Settings when editing an entry in GPEB. |
| 7 | + * |
| 8 | + * Instruction Video: https://www.loom.com/share/b9867d2735d44519bf563961e9b30bd2 |
| 9 | + */ |
| 10 | +add_filter( 'gpeb_queryer_entries', function( $entries, $gf_queryer ) { |
| 11 | + |
| 12 | + // Update the form ID to match your form. |
| 13 | + if ( $gf_queryer->form_id != 933 ) { |
| 14 | + return $entries; |
| 15 | + } |
| 16 | + |
| 17 | + // Update the field IDs to match your form. |
| 18 | + $primary_sorting_field_id = '1.6'; |
| 19 | + $secondary_sorting_field_id = '1.3'; |
| 20 | + $sorting_direction = 'ASC'; // 'ASC' or 'DESC' |
| 21 | + |
| 22 | + usort( $entries, function( $a, $b ) use ( |
| 23 | + $primary_sorting_field_id, |
| 24 | + $secondary_sorting_field_id, |
| 25 | + $sorting_direction |
| 26 | + ) { |
| 27 | + $a_primary = isset( $a[ $primary_sorting_field_id ] ) ? $a[ $primary_sorting_field_id ] : ''; |
| 28 | + $b_primary = isset( $b[ $primary_sorting_field_id ] ) ? $b[ $primary_sorting_field_id ] : ''; |
| 29 | + |
| 30 | + $cmp = strcasecmp( $a_primary, $b_primary ); |
| 31 | + if ( $cmp === 0 ) { |
| 32 | + $a_secondary = isset( $a[ $secondary_sorting_field_id ] ) ? $a[ $secondary_sorting_field_id ] : ''; |
| 33 | + $b_secondary = isset( $b[ $secondary_sorting_field_id ] ) ? $b[ $secondary_sorting_field_id ] : ''; |
| 34 | + $cmp = strcasecmp( $a_secondary, $b_secondary ); |
| 35 | + } |
| 36 | + |
| 37 | + return ( $sorting_direction === 'DESC' ) ? -$cmp : $cmp; |
| 38 | + }); |
| 39 | + |
| 40 | + return $entries; |
| 41 | +}, 10, 2 ); |
0 commit comments