I'm creating a recipe system using the many to many relationship database. I understand how to create the relationship, this isn't the issue.
Here's an example. I have Post type Called Recipes and another called ingredients. These are linked via a relationship. My issues is that some recipes have multiple recipes within them such as a cake recipe which lists the ingredients for the cake and a seperate recipe for the icing. I need to group the recipes within the recipe. But still allowing ingredients to be many to many,
How do I create two recipes and group them by name like Cake A Icing, Cake A Recipe and them have them appear in the recipe custom post type. Previously I just had a recipe CPT and allowed the user to add ingredients within using the post type ingredients.
Do I need to create a third custom post type called Recipe method and link this to the relationship so i can then select recipes within the method post type?
I have added a sample of a recipe card showing the two different recipes required for the one recipe. How do we do this using the relationship many to many?
Here is a screenshot of how it is done with a plugin, see how the ingredients can be grouped. This is what i need to achieve
Hello,
There isn't such kind of built-in feature within Toolset many-to-many relationship.
As a workaround, you can consider to use a custom post type as intermediate post type, and use a custom taxonomy to group the intermediate posts, for example:
1) Create a new post type "relationship-cpt"
2) Create a custom taxonomy "Group", assign it to above post type "relationship-cpt"
3) Setup two new one-to-many relationships:
- one-to-many relationship between post types "Recipes" and "relationship-cpt"
- one-to-many relationship between post types "ingredients" and "relationship-cpt"
So it can setup another many-to-many kind of relationship between post type "Recipes" and "ingredients" using intermediate post type "relationship-cpt".
4) In the single "Recipes" post, you can setup a nested view:
a) Parent taxonomy view:
- Query terms of taxonomy "Group"
- Display below child post view
b) Child post view:
- Query "relationship-cpt" posts
- Filter by:
b1) Select posts with taxonomy: Group set by the parent Taxonomy View
b2) Select posts in a Recipes relationship-cpts relationship that are related to the Post where this View is shown.
- Display it's parent "ingredients" post information
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent
More help:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/
OK, that would work only there are 3000 recipes and trying to keep track of the taxonomy for each recipe group may create an issue for the end users.
I think i will need to simplify the process by creating CPT repeating group for the ingredients within the recipe Post type, Just means the users will need to add new ingredients for each recipe they create. rather than build them from entered data.
Thanks.
Yes, you are right, the repeating groups are based on one-to-many relationship, it won't be able to setup many-to-many relationship, so your users will need to add new ingredients for each recipe post.
My issue is resolved now. Thank you!
I have tried to use the Repeating Group option for Custom post types to achieve what i need but i cannot get any data to output for the nested repeat group. I have attached a screenshot of the entire workflow including the custom view to show the repeat groups but i get no items found.
So for Recipes i have a custom post repeatable group that has the following
Recipe list (Repeatable Group)
- Recipe Title (Single line)
- Recipe Item (Repeatable Group)
-Item name (Single line)
I watched the video on creating the view for the repeat group but my setup is a little different as i have a nested repeat group as you will see.
Since you are using nested repeating field group, so you will need to setup nested view to display the result, for example:
1) Parent post view
- Query "Recipe list" posts
- Filter by:
Select items from the Item name group that are related to the Post where this View is shown.
- Display below child post view
2) Child post view
- Query "Item" posts
- Filter by:
Select items from the item group that are a related to the current post in the loop.
- Display item information
Then put the parent post view's shortcode into single Recipe post, and test again.