I am trying to create a football site:
So my structure is something like this:
1. We have Leagues
2. We have seasons
3. We have teams
4. We have players
Each League has multiple seasons and each season has a set of teams and each team has a set of players for each season.
I am not able to figure out how can I like and put them together? Is that possible to do using the toolset, if yes please show an example?
I already created CPTs for Seasons, Leagues, Teams, & Players, but I am not able to figure out how do I connect them.
League > Season > Team > Players
I want to connect in such a way, so I can display teams participating in a league for a particular year.
Some more insights:
1. We have 100s of Different leagues.
2. We have multiple seasons for each league.
2. We have multiple teams in each different league.
3. We will have 100s of players together in all teams.
If that does not work, please issue a refund. Thanks in advance.
Hello, in Toolset you can use post relationships to connect two custom post types. If you want to link multiple CPTs in some kind of hierarchy, you must create multiple relationships, since one relationship can only associate two custom post types. Usually you will choose between many-to-many relationships and one-to-many relationships between each pair of custom post types. Sometimes a many-to-many relationship is appropriate between two custom post types. In other cases, you might want a one-to-many relationship between two custom post types. For example, let us consider Seasons and Teams. Let us assume you have three Seasons posts:
- Season 2019
- Season 2020
- Season 2021
Now let us assume you also have three Team posts:
- Team Europe
- Team Africa
- Team Asia
Should the relationship between Seasons and Teams by One-to-Many (O2M), or Many-to-Many (M2M)? In a One-to-Many relationship where Season is the parent and Team is the child, it is not possible for Team Europe to be related to Season 2019 and also related to Season 2020. Therefore, O2M is not appropriate if you want Teams to be able to participate in multiple Seasons.
Now let us consider the relationship between Teams and Players. Can a Player belong to more than one Team? If so, you need a M2M relationship between Teams and Players. However, if a Player can only ever belong to one Team, then you could use a O2M relationship between Teams and Players, where Team is the parent and Player is the child.
It gets complicated when Player 1 belongs to Team Europe in Season 2019, but then Player 1 belongs to Team Africa in Season 2020. This is a complicated setup not easily achieved in Toolset, since each M2M relationship is independent of the other M2M relationships between other post types.
To give you a working example, I need to know what type of post relationships (O2M or M2M) you wish to create between each of the different custom post types.
How about I go this way.
I create Custom Post Types For
Seasons, Leagues, Teams, Players.
Is there a way to connect those using a group repeater field:
Example.
A team post will have the following in group repeater
Season - League
A Player Post will have the following in group repeater
Season - Team
This way we will know what seasons are played in what leagues by each team, then we can query and display as needed in league pages. Can we achieve the above scenario?
A team post will have the following in group repeater
Season - League
In a repeatable field group (RFG) assigned to the Team post type, there is no way to select an individual Season post or an individual League post to relate to each RFG row. That would require a post reference field, or some way to use post relationships with RFGs. The post reference field is not allowed in RFGs, nor is it possible to use post relationships to link individual RFG entries with other CPTs. An RFG can only be related to the post type that contains the RFG.
The best workaround I can think of would be to include a numeric field in the RFG that stores the Season Post ID, and another numeric field in the RFG that stores the League Post ID. However, this would be a manual process when entering RFG values. You would have to find the related Season and League post IDs in wp-admin, and then enter them manually in the number field when you create an RFG entry in the Team post.
Another limitation to consider here is that a View of Teams cannot be filtered by its RFG fields. It can be filtered by fields applied directly to the Team post type, but not fields in its RFGs. To filter a View by fields of an RFG, you must create a View of that RFG instead of a View of the parent post type. So if you want to display a list of Team in the League post, but you want to filter that list of Teams by the RFG values, you cannot create a View of Teams. You must create a View of RFGs instead, and filter by those RFG fields. Then in the results of that RFG View, you could display information about the parent Team post.
What if we create Custom Post Types for Teams:
Then I will have a custom field called Team ID, League ID etc and will save those.
Then can I query using that leage ID or team ID and output the desired results?
Yes, you could add a custom field like League ID or Season ID in a Team post. There's no need for an additional Team ID field, since each post has its own post ID automatically assigned by WordPress. However, this doesn't help you in a scenario where you want to relate a Team to multiple Seasons, in different Leagues:
Team 1 in Season 2020 in League A
Team 1 in Season 2019 in League A
Team 1 in Season 2018 in League B
You would need a repeatable field group here, since you need to create grouped entries.
Basically, we do not want to link at all, instead, we will save the following
For Reach Team:
Season ID League ID Player ID
We do not want to track or link with post ids.
Then is there a way that we can query and display the results?
For league ID we will look in Leagues CTPs and find the league name, for season ID we will look into Seasons CPT and pull the year and same goes with the players.
What do u think?
For Reach Team:
Season ID League ID Player ID
I assume you can have multiple Players on one team, right? If so, you need RFGs in the Team post to store grouped ID fields like this:
Season 1 ID, League A ID, Player Tom ID
Season 1 ID, League A ID, Player John ID
Season 1 ID, League A ID, Player George ID
... and so on, one RFG entry for each Player, in each season, in each league.
It could be quite tedious to implement this effectively in wp-admin, because these ID references are not maintained in both places. In other words, if you add these fields as an RFG in the Team post type, those ID references do not automatically exist in the League post type, or in the Season post type, or in the Player post type. You would need separate RFGs in each post type to maintain those references in both locations.
Also if you plan to allow your site Users to create custom searches, the fields are only filterable by this numeric ID, not by post title. So your Users would see Player filters with options like 1, 2, and 3 instead of Tom, John, and George. I'm not sure if front-end filtering is a requirement for your site, but if so, this is a serious problem that does not have a simple solution.