Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_order_lookup_options

Heads up! 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);

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Parameters

  • $values (array): All of the options in the Lookup field.
  • $field (array|object): The field the Lookup field is using.
  • $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);

Reverse the order of lookup options

Use this code snippet that will allow you to reverse the order of lookup options for a specific field ID. In this case, the field ID is 5093.

add_filter(
	'frm_order_lookup_options',
function ( $options, $order, $field = false ) {
		if ( false === $field ) {
			return $options;
		}

		$target_field_id = 5093;
		$field_id        = is_object( $field ) ? $field->id : $field['id'];
		if ( $target_field_id !== (int) $field_id ) {
			return $options;
		}

		$options = array_reverse( $options );
		return $options;
	},
	10,
	3
);
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms