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?
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: