Hi,
i have a db with two custom posts: ricetta (recipe) e ingrediente (ingredients) in a many to many relationship with one custom field quantità (quantity).
In the "multi-ricetta" view i use a multi select to filter the recipes by ingredients associated.
When i select two ingredients the results shows the sum of the recipes of the first ingredient and the second one.
I want to change this behaviour not to add but intersect the results.
When i select two/three/four/etc. ingredients i wish the recipes that are in common with the two/three/four/etc. ingredients.
If I understand this correctly you want to filter foods that contain lets say "Acqua AND Alette di pollo" not a logic that say "Acqua OR Alette di pollo"
What you need to do is edit your field relationship in the Query filter section of your view and set it to an AND logic, See Screenshot.
Hello Shane, If I understand this correctly you want to filter foods that contain lets say "Acqua AND Alette di pollo" not a logic that say "Acqua OR Alette di pollo"
Yes
I'm using the "Filter by post relationship or repeatable fields group owner:
Select posts in a Ricette Ingredienti relationship that are related to the Post with ID set by the URL parameter wpv-relationship-filter.
eg. hidden link"
I don't know where is the AND/OR select you shown me
If you need i can share a login so you can check directly.
Cheers
Thank you for the screenshot, unfortunately in this case you won't be able to use an AND logic with the relationship filter as it doesn't provide for this.
This option is available for custom fields with multiple select values as well as taxonomies but not for Post relationship ancestor filters.
Hello
I'm thinking about how to solve the problem, maybe you could use a condition based on a shortcode.
Eg Select 3 ingredients, it shows the only recipe that has those three ingredients. If they are not all present, the result is not shown.
1) create a query of ingredients filtered with "Filter by post relationship or repeatable fields group owner" -> wpv-relationship-filter
2) insert a condition in the loop where it should evaluate whether the current recipe has all the elements associated with it, when it finds the recipe with all three ingredients then it is true
The shortcode could take the parameters via $ _GET ['wpv-relationship-filter'] in order to have the id of the associated ingredients, then it would be necessary to test the recipe if it has relations with the associated ids.
I don't know if it's a good idea and I don't know how to implement it, I saw some questions on the forum but I didn't find something that is right for me. If it is feasible, can you give me some advice on how to proceed?