This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This hook allows you to modify the order of options in a Lookup field.
Usage
add_filter('frm_order_lookup_options', 'frm_set_custom_lookup_order', 20, 2);
Parameters
- $values (array): All of the options in the Lookup field.
- $order (string): The order selected in the Lookup field's options.
Examples
Basic example
The following is a basic example that shows how you can modify the order of options in a Lookup field.
add_filter('frm_order_lookup_options', 'frm_set_custom_lookup_order', 20, 2);
function frm_set_custom_lookup_order( $values, $order ) {
if ( $order == 'ascending' ) {
sort( $values );
}
return $values;
}
Order dates in lookup
If you are using Date fields in your Lookup field, you can use this code example to sort the lookup options by ascending date order.
add_filter( 'frm_order_lookup_options', 'order_lookup_date_options' );
function order_lookup_date_options( $options ) {
usort( $options, 'date_sort' );
return $options;
}
function date_sort($a, $b) {
return strtotime($a) - strtotime($b);
}
To switch to descending order, reverse the date sort function to:
strtotime($b) - strtotime($a);