Hey,
Does anyone know how to adapt this code so instead of excluding fields based on their ID, it excludes them based on their label (name)?
add_filter( 'frm_entry_values_exclude_fields', 'specify_exclude_fields', 10, 2 );
function specify_exclude_fields( $field_ids, $atts ) {
$field_ids[] = 3013; return $field_ids;
}
Here is the link to the code:
https://formidableforms.com/knowledgebase/frm_entry_values_exclude_fields/ Thank you!
Start your code here
add_filter('frm_entry_values_exclude_fields', 'specify_exclude_fields', 10, 2); function specify_exclude_fields($field_ids, $atts) { // Hard-coded form ID $form_id = 78; // Replace 78 with the actual form ID // Define a list of field labels to exclude $exclude_labels = ['Label 1', 'Label 2', 'Label 3']; // Replace these with actual labels to exclude // Fetch all fields for the form $fields = FrmField::get_all_for_form($form_id, '', 'include'); // Loop over each field and check the label foreach ($fields as $field) { if (in_array($field->name, $exclude_labels)) { // If the label is in the exclusion list, add its ID to the $field_ids array $field_ids[] = $field->id; } } return $field_ids; }
Hey,
Thanks for the advice.
I tried using the following code, but can't get it working. Do you know how it to can improved?
add_filter( 'frm_entry_values_exclude_fields', 'specify_exclude_fields', 10, 2 );
function specify_exclude_fields( $field_ids, $atts ) {
// Assume we have a list of field labels to exclude
$exclude_labels = ['Exclude Label 1', 'Exclude Label 2']; // Replace these with actual labels to exclude
// Temporary array to store field IDs that match the exclusion criteria
$fields_to_exclude = [];
// Loop over existing field IDs and check each field's label
foreach ( $field_ids as $field_id ) {
// Get the field object
$field = FrmField::getOne( $field_id );
// Check if the field's label is in the list of labels to exclude
if ( in_array( $field->name, $exclude_labels ) ) {
// If it matches, add this field ID to the fields to exclude
$fields_to_exclude[] = $field_id;
}
}
// Filter out the field IDs that match the exclusion labels
$field_ids = array_diff( $field_ids, $fields_to_exclude );
return $field_ids;
}
I don't see anything glaringly obvious and it'll be next to impossible for me to debug in absentia so I suggest setting up WP debugging and log the values in your program and it'll eventually become clear. https://wpforms.com/developers/how-to-enable-debugging-in-wordpress/
Hi,
I have lots of fields that I want to exclude from entries and they all share the same label. So instead of always having to add the field ID, I want to be able to add just the field label and therefore exclude all these fields automatically.
Thanks for the help!
Please login or Register to submit your answer