Description
Use this filter to change the $args passed to the WordPress get_terms() function and filter the list of categories displayed when a post category field is configured with the “display all categories” setting selected.
Usage
The following would apply your function to all forms.
add_filter( 'gform_post_category_args', 'your_function_name', 10, 2 );
To target a specific field append the field id to the hook name. (format: gform_post_category_args_FIELDID)
add_filter( 'gform_post_category_args_5', 'your_function_name', 10, 2 );
Parameters
- $args array
The args being filtered. See the WP_Term_Query::__construct() codex article for the possible arguments.
$args = array( 'hide_empty' => false, 'orderby' => 'name', 'taxonomy' => 'category' );
-
$field Field Object
The current post category field.
Examples
The following example demostrates how to exclude a category (category with ID=12) from the list of categories:
add_filter( 'gform_post_category_args', 'change_categories', 10, 2 ); function change_categories( $args, $field ) { $args['exclude'] = '12'; return $args; }
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::add_categories_as_choices() in common.php.