Created
April 7, 2020 17:11
-
-
Save vfontjr/bfab087f91edb65b4fa16fc00ba3984f to your computer and use it in GitHub Desktop.
Snippet to retrieve filtered values from a specific Formidable form and populate a dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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