Lookup radio button option display order set by field value

By: Phil Cox | Asked: 07/18/2022
ForumsCategory: Code SnippetsLookup radio button option display order set by field value
Phil Cox asked 2 years ago
Hi, I want to control the display order of the options in a lookup radio button field.  The options lookup from entries on another form "city".  One of the fields on that form is "Display sequence".  So the "city" entries "city, display sequence" are: "London, 1", "Amsterdam, 2", "Zanzibar, 3". None of the provided snippets in the FF documentation seem to help with this.  Has anyone solved this in the past? Thanks, Phil.
Bobby Clapp replied 2 years ago

https://formidableforms.com/knowledgebase/frm_order_lookup_options/#kb-basic-example is the closest snippet you'll find. Depending on what you want to do you may have to create your own SQL query.

Phil Cox replied 2 years ago

Thanks Bobby. I looked at that snippet in my discussion with FF support, but they stated:
"You can only use to hook to order in descending /ascending order."

As you say, it would need some customisation.

1 Answers
Victor Font answered 2 years ago
Phil, If you look at the PHP code in this tutorial, I'm populating a dropdown dynamically from a lookup table and ordering the results by value. Your radio buttons would require similar code. The SQL call has its own function since I'm using the same SQL in two places. https://formidable-masterminds.com/create-interactive-graphs-with-chart-js-and-formidable/
Phil Cox replied 2 years ago

Thanks, Victor - there's certainly plenty going on in that example! So for my scenario, I have used your approach and reshaped your code as follows:

add_filter('frm_setup_new_fields_vars', 'masterminds_populate_city_lookup', 20, 3);
function masterminds_populate_city_lookup( $values, $field, $args ) {
if ( $values['field_key'] == 'city_dropdown' ) {
$lu_results = masterminds_icpfrm_config();
$newoptions = array( 0 => array('label' => 'Select a city:') );
foreach ( $lu_results as $lu_entry ) {
$newoptions[] = array('label' => $city_name>dropdown_label;
$values['options'] = $newoptions;
return $values;

function masterminds_icpfrm_config() {
global $wpdb;
/* create the variables for the formidable tables */
$wpdb_prefix = $wpdb->prefix;
$frm_items_table = $wpdb_prefix . 'frm_items';
$frm_item_metas_table = $wpdb_prefix . 'frm_item_metas';

/* get target field IDs */
$city_id = FrmField::get_id_by_key('city_name');
$dropdown_label = FrmField::get_id_by_key('irclu_dropdown_label');
$display_sequence = FrmField::get_id_by_key('display_sequence');

/* create SQL SELECT
* if you have many configuration fields, you can also use a SQL View
$sql = "SELECT city_name, display_sequence FROM city_entries ORDER BY display_sequence;";

return $wpdb->get_results($sql);

I'm unsure about the "irclu_dropdown_label". I can't tell if it can be removed or if it is essential and simply needs renaming.

Am I going in the right direction?

Victor Font replied 2 years ago

That’s the field key for the input to be populated.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community