Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Snippet to retrieve filtered values from a specific Formidable form and populate a dropdown
<?php
add_filter( frm_setup_new_fields_vars, frm_populate_classes, 20, 2 );
add_filter( frm_setup_edit_fields_vars, frm_populate_classes, 20, 2 ); //use this function on edit too
function frm_populate_classes( $values, $field ){
global $wpdb;
$prefix = $wpdb->prefix;
$frm_items = $prefix . 'frm_items';
$frm_item_metas = $prefix . 'frm_item_metas';
if( $field->id == '203' ) {
$sql = "SELECT t1.meta_value FROM `{$frm_item_metas}` t1 LEFT JOIN `{$frm_items}` t2 ON t1.item_id = t2.id LEFT JOIN `{$frm_item_metas}` t3 ON t1.item_id = t3.item_id WHERE t1.field_id = '152' AND t2.form_id = '15' AND t3.field_id = '153' AND t3.meta_value = 'Class' ORDER BY t1.meta_value";
//the Query
$dataset = $wpdb->get_results( $sql, ARRAY_A );
unset($values['options']); //break the binding of any existing content in the values array
$values['options'][]="";
//the Loop
if(! empty($dataset)){
foreach( $dataset as $class ){
$values['options'][] = $class['meta_value'];
}
}
}
return $values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.