Skip Navigation

[Resolved] Displaying Multiple Relationships between Two Types

This support ticket is created 4 years, 1 month 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 3 voices.

Last updated by albertB-4 4 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1837851
Screenshot 2020-11-08 at 12.42.01.png

Hi! I have two Types on my site: Creators and Shows.

The same Creator can have multiple different jobs on a given Show (Director, Writer, Actor), so I can't make different post types for each different job. Instead, I'm creating multiple Many-to-Many Relationships betweeen Creators-Shows for each different job they can have.

How do I build a Content Template to display these different relationships? Should be rather straightforward, but I'm getting lost because it's a bit more complex than the Toolset video course. I don't understand what Intermediary Posts do, exactly.

Attached is an image from IMDb of what I want to accomplish.

Thanks in advance!

#1838553

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

There is a limitation currently with Toolset relationships which means you cannot have multiple connections between the same posts that is a problem here.

If I were connecting Creators to Shows, I would store the role of the creator on a given show in a relationship custom field. (The purpose of an intermediate post type is a place to store such custom fields, because they don't belong on either of the main post types.)

So, take the recent Spiderman films.

Stan Lee has a writing credit, but also has an acting credit.

So ideally you would make one connection between Spiderman and Stan Lee where the relationship field for credit is "Writer", then you would make a second connection between Spiderman and Stan Lee where the credit field is "Actor".

Then you can use a View to return all of the Creators who had an Acting credit on Spiderman, and another View to return all of the Creators who had a Writing credit on Spiderman, etc.

But right now Toolset doesn't let you make multiple connections between the same posts, so a single relationship with a credit custom field won't work here.

Instead you need a separate relationship for every kind of credit, so join Creators and Show in a "Writers" relationship, and join Creators and Show in an "Actor" relationship, etc. for every kind of credit.

Then in the template for a Show, you can display its Actors simply enough by adding a View of Creators with a relationship filter for the Actor relationship. And you create another View for the Writer relationship, and as many Views as you need for each relationship for each kind of credit.

#1838593

Hi Nigel, thanks so much for the fast reply! I'm getting closer to my goal.

1. Can I add a "relationship filter" in the blocks editor? I found the filter once I created a view in the legacy editor, but that's much less intuitive to use and I'd prefer not to.

2. I'm also having trouble displaying and querying custom fields. My views aren't displaying them via shortcode, and in queries it claims there aren't any posts, when there definitely are (published ones, not drafts!).

[EDIT for #2] Concretely: I'm (1) trying to display a custom string after the name of my credit (Head Writer, Co-Writer etc) and (2) trying to sort my credits by a priority number I defined as a custom field, but when I try to set that as the order, it says there aren't any posts.

Thanks.

#1839091

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2020-11-09 at 10.56.52 AM.png

Hi Albert,

1. Can I add a "relationship filter" in the blocks editor? I found the filter once I created a view in the legacy editor, but that's much less intuitive to use and I'd prefer not to.

Yes you can add a relationship filter using the block editor. See Screenshot

2. I'm also having trouble displaying and querying custom fields. My views aren't displaying them via shortcode, and in queries it claims there aren't any posts, when there definitely are (published ones, not drafts!).

I would need to check the site to see what is happening here. Can you allow me to have admin access to the site as well as a link to the page where the view is so that I can have a look.

Thanks,
Shane

#1841347

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Albert,

1. I wasn't looking for a dynamic filter, just to be able to edit the Query Filter for the view. That doesn't seem to be editable in Gutenberg, right? But I've gotten used to the classic editor so that's solved for now.

It is still possible to add a static relationship filter with blocks. To do it you will need to select the view in the block navigator in the top left hand corner. Then on the blocks tab in the right hand side you will need to scroll to the query filter section and add your query filter from there.

2. Regarding the sorting issue. I've found the problem. The field that you are sorting for is the on the intermediary post type.
The first thing you will need to do is to enable "publicly queryable " so that you can create a view for this.
hidden link

So you will need to create another layer of the view, so you will need to create the intermediary post type view and then add your Post relationship filter to the intermediary view and then add your current child view inside your intermediary view <wpv-loop>

Finally just add the sorting to the intermediary post view and it should sort the current child view correctly.

For the current child view as well you will need to set the current query filter to "The current post in the loop".

Please let me know if this resolves the issue now.

Thanks,
Shane

#1845935

Hi Shane,

thank you, and sorry for the late response. I tried implementing your suggestion, but it's a few steps beyond my current understanding of Toolset. Could you please point me to the right course lessons to understand intermediary post type views and child views? I can't seem to find the right tutorial.

Thanks,
Albert

#1846701

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Albert,

There isn't a documentation that can guide you specifically on this. To be able to do this require's knowledge of what you can actually do in toolset. Our Documentation won't show everything that is possible. It will discuss the basics to get you started.

For e.g intermediary posts are mentioned in this document below but it doesn't mention that it can be used in a view etc.

https://toolset.com/course-lesson/many-to-many-post-relationships/#setting-up-many-to-many-post-relationships

Can you let me know exactly where you are stuck and send the link so that I can help better?

Thanks,
Shane

#1847221
Screen Shot 2020-11-17 at 12.05.05.png
Screen Shot 2020-11-17 at 12.07.21.png

Hi Shane,

thanks for the link. As soon as I choose "Creators that are related to the current Show", I get a Query Filter that I can't edit – but it's choosing the wrong relationship for me (img. 1). I have several Many-to-Many-Relationships going on, so I need the edit option.

If I pick "All Creators" and set a filter manually for the relationship I need, I can no longer choose an intermediary post as my post source (img. 2), and therefore can't display and relationship custom fields...

Thanks,
Albert

#1847735

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Albert,

The setup that you want to achieve isn't possible to do with Blocks.

That is because you are not able to nest the views in blocks, so you won't be able to sort by the intermediary CPT field.

If you like I can set this up for you so that you can have a working example.

Please let me know.
Thanks,
Shane

#1848817

Thank you for your help, Shane! I was able to solve my problem with the links you provided and the info that it wasn't possible in Blocks. I worked it out in the classic editor.