Description

Le filtre wpforms_dynamic_choice_taxonomy_args est utilisé pour peupler les Choix Dynamiques pour les termes de taxonomie tels que les catégories et les étiquettes.

paramètretypedescription
$argstableau (requis)Arguments pour récupérer les termes de taxonomie. Par défaut :
taxonomy chaîne. La taxonomie sélectionnée dans les paramètres du champ, par exemple category ou post_tag.
hide_empty bool. Si les termes sans articles doivent être masqués. Par défaut false
$fieldtableauParamètres et propriétés du champ nettoyés pour le champ Choix Dynamiques.
$form_datatableauID du formulaire.

Source

wpforms/includes/admin/ajax-actions.php

Exemple

/**
 * 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 );

Article de référence