Tell us what you are trying to do?
Hi- I have a recipe search with checkboxes for each ingredient.
I want it so that recipes that appear in the search results can ONLY contain ingredients that the user checked off. If a recipe contains even one ingredient that was NOT checked off, the recipe should not appear in the results. But each recipe does not need to include ALL of the ingredients the user checked off.
Example. User checks off the following ingredients:
• Chicken breast
• Broth
• Carrots
• Peas
• Rice
• Cheddar Cheese
• Ground beef
Following recipe would show up in results because it only contains ingredients the user checked off - even though it does not include all the ingredients user checked off.
Chicken Rice Soup
Ingredients:
• Chicken breast
• Broth
• Rice
• Carrots
Following recipe would NOT show up in results because it contains an ingredient the user did not check off
Chicken Noodle Soup
Ingredients
• Chicken Breast
• Broth
• Carrots
• Noodles – not checked off by user
I can't get this to work.
Is there any documentation that you are following?
Is there a similar example that we can see?
hidden link
What is the link to your site?
Hello,
How do you setup the "recipes" and "ingredients"?
Is the "recipes" a custom post type?
Is the "ingredients" a custom post taxonomy or custom checkboxes field?
I need to test it in my localhost, thanks
Hi Luo,
Yes, “Recipes” is a custom post type.
For the ingredients, I have set up taxonomies for each major ingredient category - for example: “Meats”, “Vegetables” , etc. Within each of these taxonomies are individual ingredient choices – for example, within “Meats” taxonomy I have choices for “chicken”, “beef”, “pork”, etc. Each recipe on the backend is associated with the applicable taxonomy ingredients.
On the frontend, I have set up each of these ingredient taxonomies as checkboxes. So there is a set of checkboxes for all the different Meats ingredients, Vegetables ingredients, etc.
Under “Query Filters” I have set up a taxonomy filter for each of these ingredient taxonomies. But I can’t figure out how to set up the filter so that the results return recipes that ONLY contain ingredients that the user checked off – nothing more. And at the same time, each recipe does not need to include ALL of the ingredients the user checked off.
Thanks for the details, unfortunately, there isn't such kind of built-in feature within Toolset plugins, Toolset Blocks/Views plugins are using WordPress built-in class WP_Query to query and filter the posts, see WP document:
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
No such kind of taxonomy filter can fit for your case.
You might consider custom codes, for example, create a custom shortcode to check if current "Recipes" post satisfied the specific condition:
https://developer.wordpress.org/reference/functions/add_shortcode/
Then in view's loop, use above custom shortcode as condition of [wpv-conditional] shortcode, and display the result:
https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/