Skip Navigation

[Resolved] Many-to-many relationships in Toolset

This thread is resolved. Here is a description of the problem and solution.

Problem:
The structure ist as follows:

A. Events / bands
- Each location can have one or multiple events.
- Each band can have one or multiple events.
- These post type are connected via an intermediary post type "appearances" (Child of Events and Bands)

B. Bands / artists
- Each band with some text can have multiple artists.
- Each artist with some photo and text can be in multiple bands
- These post type are connected via an intermediary post type "membership" (Child of Events and Bands)

Now I would like to be able to display on a same page fields from the event post type and - and thats the hard part - fields from the artist post type: I would like to be able to print a page that contains the field from the event (Date, time, location), fields from the band (band name) and fields from the artist (each artists bio and photo). Since artists have no direct connection to events, because the band is the direct connection, I cannot figure out how to do this.

Solution:
I assume we are talking about below case:
1) Parent post types "events" and "bands"
Child post type "appearances"

2) Parent post type "bands" and "artists"
Child post type "membership"

And you are going to achieve this:
In a single "artist" post, display the information of related "event" posts

This is possible, I suggest you try with a nested view
1) Parent view list "membership" posts, filer by "Post relationship filter":
Select posts that are children of the Post where this View is shown.
2) In the view's loop, you will be able to display those related "bands" posts, for example you can get the "band" post ID with shortcode [wpv-post-id id="$bands"], display content template of steps 3) and specific id attribute, for example:
[wpv-post-body view_template="band-post-info" id="[wpv-post-id id="$bands"]"]

3) Create a content template "band-post-info", display the view of step 4)

4) Create a view, list "appearances" posts, filer by "Post relationship filter":
Select posts that are children of the Post where this View is shown.
And display the custom fields of "events" posts

Relevant Documentation:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

This support ticket is created 7 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by marcS-7 7 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#559341

Hello,

I have following use case: I have setup an Events system for music , very similar to your example on https://toolset.com/documentation/toolset-training-course/part-9-many-to-many-relationships-in-toolset/, The structure ist as follows:

A. Events / bands
- Each location can have one or multiple events.
- Each band can have one or multiple events.
- These post type are connected via an intermediary post type "appearances" (Child of Events and Bands)

B. Bands / artists
- Each band with some text can have multiple artists.
- Each artist with some photo and text can be in multiple bands
- These post type are connected via an intermediary post type "membership" (Child of Events and Bands)

Now I would like to be able to display on a same page fields from the event post type and - and thats the hard part - fields from the artist post type: I would like to be able to print a page that contains the field from the event (Date, time, location), fields from the band (band name) and fields from the artist (each artists bio and photo). Since artists have no direct connection to events, because the band is the direct connection, I cannot figure out how to do this.

I thought about finding a way to copy fields from one post type over to another one?
Else, I am hoping for the hopefully soon to be released post relationship project

But maybe you have a better suggestion or would know in which direction I should search.

Thank you in advance.
Marc

#559465

Dear Marc,

I assume we are talking about below case:
1) Parent post types "events" and "bands"
Child post type "appearances"

2) Parent post type "bands" and "artists"
Child post type "membership"

And you are going to achieve this:
In a single "artist" post, display the information of related "event" posts

This is possible, I suggest you try with a nested view
1) Parent view list "membership" posts, filer by "Post relationship filter":
Select posts that are children of the Post where this View is shown.
2) In the view's loop, you will be able to display those related "bands" posts, for example you can get the "band" post ID with shortcode [wpv-post-id id="$bands"], display content template of steps 3) and specific id attribute, for example:
[wpv-post-body view_template="band-post-info" id="[wpv-post-id id="$bands"]"]

3) Create a content template "band-post-info", display the view of step 4)

4) Create a view, list "appearances" posts, filer by "Post relationship filter":
Select posts that are children of the Post where this View is shown.
And display the custom fields of "events" posts

More help:
Displaying Fields of Parent Pages
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

#561110

Hi Luo,
sorry for getting back so late and thank you very much for the fast reply.
Your recommendations helped, I will try this way.
Will get back, should I need more assistance.
Regards, Marc