Description

The wpforms_dynamic_choice_taxonomy_args filter is used to populate the Dynamic Choices for taxonomy terms such as categories and tags.

parametertypedescription
$argsarray (required)Arguments for fetching taxonomy terms. By default:
taxonomy string. The taxonomy selected in the field settings, e.g. category or post_tag.
hide_empty bool. Whether to hide terms without posts. Default false
$fieldarraySanitized field settings and properties for the Dynamic Choices field.
$form_dataarrayForm ID.

Source

wpforms/includes/admin/ajax-actions.php

Example

/**
 * Limit taxonomy terms displayed in a Dynamic Choices field.
 *
 * @link https://wpforms.com/developers/wpforms_dynamic_choice_taxonomy_args
 *
 * @param array $args     Arguments from taxonomy query.
 * @param array $field    Sanitized field data.
 * @param int   $form_id  Form ID.
 *
 * @return array Updated arguments
 */
function wpf_dev_dynamic_choices_taxonomies( $args, $field, $form_id ) {
    
    // Only run on form #456 and field #12
    if ( $form_id == 456 && $field['id'] == 12 ) {
        
        // Include categories with IDs 25, 26, and 27
        $args['include'] = '25,26,27';
    }
    
    return $args;
}
add_filter( 'wpforms_dynamic_choice_taxonomy_args', 'wpf_dev_dynamic_choices_taxonomies', 10, 3 );

Reference Article