Hello, there's nothing built-in that will help you filter the categories in a Form field from the Form builder, but you can use a custom code snippet to restrict those terms with PHP. It's a manual process, so you would have to whitelist each individual term. The following code can be adjusted for your needs:
/**
* Blacklist or whitelist terms in a taxonomy form field or View filter
*/
function tssupp_restrict_terms( $terms, $taxonomies, $args, $term_query ){
// 1. pages where form (or search View) is inserted
$pages = array( 118, 137 );
// 2. which taxonomy (slug)
$taxonomy = 'status';
// 3. add terms to blacklist *OR* whitelist, not both
$blacklist = array();
$whitelist = array( 'archived', 'completed' );
if ( is_page( $pages ) && $taxonomies[0] == $taxonomy ) {
if ( !empty( $blacklist ) ) {
foreach( $terms as $key => $term ){
if ( in_array( $term->slug, $blacklist ) ) {
unset($terms[$key]);
}
}
} elseif ( !empty( $whitelist ) ) {
foreach( $terms as $key => $term ){
if ( !in_array( $term->slug, $whitelist ) ) {
unset($terms[$key]);
}
}
}
}
return $terms;
}
add_filter( 'get_terms', 'tssupp_restrict_terms', 10, 4 );
You must adjust the pages array to include a comma-separated list of the page or post IDs where this Form is shown:
$pages = array( 118, 137 );
You must adjust the taxonomy slug to match the appropriate taxonomy. For the built-in category taxonomy, you would use 'category' instead of 'status':
You must adjust the taxonomy term slugs to whitelist individual terms for the field:
$whitelist = array( 'archived', 'completed' );
Include each term in quotation marks as shown above, separated by a comma.
You can add that code in your child theme's functions.php file, or in a custom code snippet in Toolset > Settings > Custom Code.