Skip to content

Commit 6a981d2

Browse files
authored
gppa-sort-by-time-field.php: Added new snippet.
1 parent 3957cb6 commit 6a981d2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Populate Anything // Sort by Time Field
4+
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
5+
*
6+
* Sort times chronologically when populating a Time field from Gravity Forms entries into a choice based field.
7+
*
8+
* Usage:
9+
*
10+
* 1. Install this code as a plugin or as a snippet.
11+
* 2. Change your form and field ID below
12+
*/
13+
// Change `123` to your form ID and `4` to your populated field ID
14+
add_filter( 'gppa_input_choices_123_4', function( $choices, $field, $objects, $field_values ){
15+
16+
usort( $choices, function( $a, $b ) {
17+
$timeA = strtotime( $a['text'] );
18+
$timeB = strtotime( $b['text'] );
19+
return $timeA - $timeB;
20+
});
21+
22+
return $choices;
23+
24+
}, 10, 4 );

0 commit comments

Comments
 (0)