Sometimes when you're populating a dynamic field with information from another form's entries, you only want certain ones - like entries where another field matches some criteria or other.
In cases like that, do this:
function filter_dfe_options($values, $field){
// Filter dfe entries list to only include 'something' entries
if ( $field->id == 1181 && !empty( $values['options'] ) ) { //Replace 1181 with the ID of your dfe field
$temp = $values;
$temp['form_select'] = 30; //change 30 to the id of the field (in linked form) that you want to filter by
$field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field );
foreach ( $values['options'] as $id => $v ) {
if ( isset( $field2_opts[$id] ) && ( $v == '' || $field2_opts[$id] == 'something' ) ) {
// Optional: only include values where filtering field equals "something"
continue;
}
unset( $values['options'][$id] );
}
}
return $values;
}
add_filter('frm_setup_new_fields_vars', 'filter_dfe_plan_options', 25, 2);
Hi! I would like to know if you could explain how to change the fixed 'something' value with a user meta variable. I want to filter by the user's team (meta key 'users-team').
Here's what I have so far:
add_filter('frm_setup_new_fields_vars', 'filter_dfe_options', 25, 2);
function filter_dfe_options($values, $field){
if ( $field->id == 100 && !empty( $values['options'] ) ) {//Replace 100 with the ID of your Dynamic field
$temp = $values;
$temp['form_select'] = 123;//change 123 to the id of the field (in linked form) that you want to filter by
$field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field );
$user_id = get_current_user_id();
$key = 'users-team';
$single = true;
$user_team_match = get_user_meta( $user_id, $key, $single );
foreach ( $values['options'] as $id => $v ) {
if ( isset( $field2_opts[$id] ) && ( $v == '' || $field2_opts[$id] == $user_team_match ) ) {//Only include values where filtering field equals Yes
continue;
}
unset( $values['options'][$id] );
}
}
return $values;
}
Sorry I took so long to respond. Not sure if you need a reply anymore.
At first glance, this looks correct, although I take it from your question that it wasn't actually working.