Let's say I want to have a drop down Search Field called Diet and then choose the categories Vegan, Gluten Free, and Paleo to be the options. Is that possible?
Hi, I assume there are currently other terms in the category taxonomy as well, right? If so, I think the only way to achieve this type of filtered filter would be to use custom code. The Block Editor does not currently have any options that would allow you to choose which terms to include in a taxonomy filter, so all the applicable terms from a taxonomy will be displayed in its filter by default. You could create your own custom taxonomy called "Diet" and place only those 3 terms in the Diet taxonomy, but then the Diet taxonomy would have to be managed independently of the standard Category taxonomy.
I have a custom code snippet available you could customize for your own site if you'd like to explore that option:
/**
* 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( 123, 456 );
// 2. which taxonomy (slug)
$taxonomy = 'category';
// 3. add terms to blacklist *OR* whitelist, not both
$blacklist = array();
$whitelist = array( 'paleo', 'gluten-free', 'vegan' );
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 would change 123, 456 to be a comma-separated list of numeric Page IDs where this View will be displayed, and change 'paleo', 'gluten-free', 'vegan' to be a comma-separated list of slugs for the terms you would like to appear in the filter options. Each term slug should be enclosed in single quotation marks. Then add the code snippet in your child theme's functions.php file, or create a new code snippet in Toolset > Settings > Custom Code and add the code to the end of the snippet.
Let me know if you have questions about that.
I don't think this will work, because I would not be able to select Paleo, Gluten-free, or vegan and display those results. I believe I have create New/Custom Taxonomies, which I know Toolset does. I did that and now I can have a Diet Dropdown and create Vegan, Paleo, and Gluten-free Within that Taxonomy. The only issue now is adding posts to this new taxonomy. Is there way bulk way to do this? I am unsure if this is easy to do through WP, if Toolset can do this, a different Plugin can do this?
My issue is resolved now. Thank you!