Skip Navigation

[Closed] Different "roles" of the same type posts in a many-to-many relationship

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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 4 years, 1 month ago.

Author
Posts
#1794779

Hi Guys,

I am working on my first site with a many-to-many relationship and pretty much everything is going very smoothly, but I don't know how to achieve one thing.

Here's the scenario:

There are two CPTs involved: Games and Teams.

Each game is related to two teams, and each team can be related to an unlimited number of games.
Inside the Team CPT we import various data dynamically from APIs. Then, inside the Game CPT there are Views with these 2 Team posts.

In every game there is the Home Team and the Away Team, and I don't know how to distinguish between these "roles" in a relationship.

For example, the View with the Home Team data should appear before the same View with the Away Team.

I do have also a taxonomy for Games (Home Teams / Away Teams), but this will not work because the API URLs must be generated dynamically. Also adding custom field options for each new team in the Game CPT is not sustainable in the long run, as the content will be created by editors.

Is there a way to distinguish between the status/role of different posts of the same type in a relationship with another post type?

Greetings,
Tom

#1795301

Nigel
Supporter

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

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

If you were adding this content via the post edit screens then I'd say the solution is straightforward.

You create a M2M relationship between Games and Teams, and you include a relationship field (stored on an intermediate post type) to store whether the team is the away team or home team for this particular game, so a radio or select field would seem appropriate.

Say you have a game post for the Liverpool vs Arsenal match in the 2020/21 season. The game post itself might store some data such as the date and attendance. You connect the Liverpool team to it, and for that connection you set the relationship field to Home. You connect the Arsenal team post to the same game post and set the relationship field to Away.

When you want to set up the return match later in the season, you connect Liverpool to a new game post and this time set them to Away, and connect Arsenal and this time set them to Home.

So the relationship fields (stored on an intermediate post) are particular to the connection.

I suggest you try it manually in the post edit screens so that you are happy you understand how it works. Then you can consider how to fit it in to your workflows using imported data.

See the following links about importing related data:

https://toolset.com/course-lesson/importing-content-from-csv-with-post-relationships/
https://toolset.com/course-lesson/import-posts-from-csv-with-relationships-using-wp-all-import/
https://toolset.com/course-lesson/how-to-import-posts-from-csv-files-and-maintain-relationships-when-using-the-csv-importer-plugin/

The topic ‘[Closed] Different "roles" of the same type posts in a many-to-many relationship’ is closed to new replies.