Description

The wpforms_dynamic_choice_post_type_args filter is used to populate the Dynamic Choices for post types and taxonomies.

Parameters

$args
(array) (Required) Arguments from the post submission such as Category ID, Tag ID, Author ID, etc.
$field
(array) Sanitized entry field values/properties.
$form_id
(int) Form ID.

Source

includes/functions.php

More Information

The wpforms_dynamic_choice_post_type_args filter provides a list of supported arguments from the post such as Category. Similarly, you can also use the wpforms_dynamic_choice_taxonomy_args to pull arguments from the taxonomy of Tags.

In this example shown below, the function will process on form ID 789 for field ID 10 and only include posts from the category 11.

Examples

/**
 * Limit posts or pages displayed by category.
 *
 * @link https://wpforms.com/developers/wpforms_dynamic_choice_post_type_args
 *
 * @param array $args       Arguments from post submission.     
 * @param array $field      Sanitized field data. 
 * @param int   $form_id    Form ID
 *
 * @return $args
 */

function wpf_dev_dynamic_choices_categories( $args, $field, $form_id ) {
    
     // Only on form #789 and field #10
     if ( $form_data[ 'id' ] == 789 && $field[ 'id' ] == 10 ) {

         $args[ 'category' ] = '11';		 
    
     }
	
     return $args;
}

add_filter( 'wpforms_dynamic_choice_post_type_args', 'wpf_dev_dynamic_choices_categories', 10, 3 );

Tutorial Reference: How to Exclude Posts, Pages or Categories From Dynamic Choices

FAQ

Q: How can I show only the child categories?

A: If you want to include the child categories in your list, you must also include those ID numbers as well as the parent ID number. It’s important to remember that you must have both the parent and the child category IDs listed.

/**
 * Limit posts or pages displayed by category.
 *
 * @link https://wpforms.com/developers/wpforms_dynamic_choice_post_type_args
 *
 * @param array $args       Arguments from post submission.     
 * @param array $field      Sanitized field data. 
 * @param int   $form_id    Form ID
 *
 * @return $args
 */

function wpf_dev_dynamic_choices_include( $args, $field, $form_id ) {

    if ( is_array( $form_id ) ) {
        $form_id = $form_id[ 'id' ];
    }

    // Only on form #122 and field #11
    if ( $form_id == 122 && $field[ 'id' ] == 11 ) {

    // Category IDs to include - 87 is a parent; 88 and 89 are child categories of this parent
        $args[ 'include' ] = '87,88,89';
    }

    return $args;

    }
add_filter( 'wpforms_dynamic_choice_taxonomy_args', 'wpf_dev_dynamic_choices_include', 10, 3 );