Many-to-many relationship allows you to connect a post of type A to many posts of type B and vice versa. For example, an "event" has multiple "speakers" and a "speaker" can appear in multiple "events".
To set-up many-to-many relationship between posts, go to Toolset → Relationships. Choose the Many-to-many option and follow the wizard to choose the posts to connect.
One of the wizard step is to add fields to the relationship. This option is only available for many-to-many relationships.
Let’s look at a few examples to see what this does.
|Event website||Events <> Speakers||Lecture title, time, location, description|
|Recipe||Dish <> Ingredient||Order, quantity|
|Music albums||Albums <> Songs||Track number|
When you add “relationship fields”, you are creating what we call an “intermediary item” for the relationship. This intermediary will hold the custom fields of the relationship. You can display these fields or use them as conditions.
After creating a relationship between two kinds of posts, you will see a box at the bottom of the post editor. It allows you to connect between posts.
From here, you can connect existing posts or create new ones that will immediately appear connected.
With Toolset, it is very easy to display related posts.
The most common way to display related posts is when editing a Content Template of a type that’s in a relationship. For example, when we’re designing the template of an “event”, which is related to “speakers”.
Since it’s a many-to-many relationship, almost always, you will display related posts using a View. A View lets you load content from the database and display it as a list, with any styling that you choose.
All you have to do is insert the View block and in the creation wizard, select which related content it should display.
Now, proceed to design the View.
In this View, you can also display fields that belong to the relationship. For example, when we list the speakers, we often want to show the titles of their lectures. To display fields that belong to the lecture (the relationship), insert any Toolset block that you want and enable Dynamic Source. Then, in the Post source, select the relationship. Now, you can choose fields that belong to the relationship.
- How to Create Custom Searches and Relationships for Users
- Using Post Reference Field to Set-Up One-to-Many Relationships
- Selecting Parent Posts when Using Forms to Create Child Items
- How to set up Post Relationships in WordPress
- Front-End Forms for Connecting Related Posts
- Displaying Related Posts
- What Are Post Relationships and How They Work