• Phillip Burger

    (@phillipburger)


    I need some input about the optimal way to structure my Custom Post Types, Categories and (if needed) Tags.

    Thanks so much in advance for reading this. I do understand the ideas of CPT and Categories and have created and used them before, but I am putting myself in circles trying to figure out how to structure this properly.

    What I am looking to do is show stats related to sports and ultimately show them at different “hierarchy levels”:
    Players
    Teams
    League
    Matchup (2 teams)

    Player would be a CPT for a single player with their information and would show hierarchy up to the current team they are on as well as the league they play in (league the team is in). I would be able to set the player name, the stats, link them to the team they are on (which ideally links them automatically to a league) as well as upload a picture.

    Team seems like it needs to be a CPT because it needs to show specific information for the team but also list all the players that are currently on the team. I would be able to set team name, some stats and basic information, link them to a league and upload a logo picture.

    League seems to be a hierarchy of Player and Team and just needs to list all teams and either all or top players in the hierarchy

    Matchup needs to be dynamic and just show some of the information from the 2 teams in the matchup and maybe key players from each

    Where I am going around in circles is making sure I have explained this right that it seems I need 2 CPTs and a single hierarchy that connects them as well as ???? for the Matchup to make it dynamic.

    How can I like a player to a team (a hierarchy) but also have the team as a CPT? Is that a linking or do I create a Team CPT and also a team_category for all the players?

    While entering the data I can make sure it makes sense to only put players in teams in the right league, but for matchups, just need to verify the matchup makes sense (I cannot look for a matchup between the Boston Red Socks and LA Lakers – different leagues).

    What makes sense to use for the matchup? It is not a CPT because I do not want to create all the various data points, just make it dynamic that if the selection is NBA/bos-okc or something, it just shows Boston Celtics vs OKC Thunder information.

    Last – how about URL structure? I wanted to make it logical like <league>/<team> and <league>/<team>/<player> or maybe just <league>/<player> and then something like <league>/matchup/<team1>-<team2> but I am confusing myself. If Player and Team are CPTs, they each need to be start of the URL and I would actually have something like:

    player/<league>/<player-slug>
    team/<league>/<team-slug>
    (or no <league> in those??)
    <league> – just to list the league category information

    matchup/<league>/<team1>-<team2>

    Thanks so much for any input. I am sure the answers are much shorter than the explanations.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Part of the problem is there are potentially a number of possible solutions. It’s difficult for anyone else to decide which would be best for you. We cannot hope to grasp your needs as well as you can.

    One hindrance is you cannot directly relate two different post types through default WP relations. You can have player posts relate directly to team posts only if they belong to the same hierarchical post type. That works conceptually, but actual labeling gets a little messy. What do you call a post type that is for both teams and players that makes sense to us humans?

    Some site owners have related different post types by using a parallel taxonomy. There is a post matching every taxonomy term. We can thus get a post that has the same slug as an assigned taxonomy term. The redundancy of data kind of makes my skin crawl, but it has worked for some.

    You could relate differing post types through a custom field (post meta). For each player, you can enter their team post ID or slug in a custom field. Thus you can get all players on a team or get a team for any given player. It’s not a formal hierarchy, but it’s as close as you can get to directly relating two different post types.

    It may be you don’t really need multiple post types or formal hierarchies. We can save all manner of taxonomy term data in term meta. It may be possible that teams could be strictly taxonomy terms without being a post type. All data like wins, losses, coaching staff, etc. can be stored in term meta. Then you can merely assign a team taxonomy term to every player post and query for team players by simply making a taxonomy post query. Same goes for leagues.

    There are pros and cons for every scheme. Don’t worry about permalinks until you’ve decided on your data schema. Just about any permastruct is possible with custom rewrite rules. Just be sure all possible permalinks are unambiguous. It’s very helpful to have some sort of “base” parameter that is always present and indicates a particular structure which cannot be confused with anything else. For example, if all pro basketball related permalinks began with “/nba/”, the rewrite rule can reliably match that and know that the subsequent terms all have a specific purpose.

    Thread Starter Phillip Burger

    (@phillipburger)

    @bcworkz I appreciate the lengthy reply. Yeah, I did not expect anyone would have a single solution to everything, but it is helpful to hear some other input.

    Because the “team” and “player” seem to match closest to a CPT, “league” seems like a hierarchy and “matchup” is a way to pair the data, I may look into building something like that and just run into problems as they come up.

    It may not make sense to create a single CPT that works for both team and player because the information and linking that comes from them is a bit different. Even if not a technical hierarchy, a team has a bunch of players linked and that player has a team so I at least need some way to store the linking information so I can dynamically link them around to each other.

    Probably one piece I need to just get past is the permalink structure does not have to be perfect. Once you are on the site or finding individual pages in a search engine, the Title attribute or linking is more important than the structure being as perfect as I want it to be.

    So it does lead me to one piece I am just not too sure of – how to build the identification of a matchup and calculate the information to display? I know technically how to do it but it is not technically a CPT since I am not going to go in and define every one of them, I want to instead just allow any possible combination of teams (must be in the same league) matchup page dynamically get created. Ideally I would like that information populated into a sitemap for search engine ranking, but it is not about entering the data for each, just dynamic creation. Thoughts about best WP-specific structure to do that? Like I said, the coding part is not the problem I have, but how would this be defined in WordPress so I could do: /matchup/nba/team1/team2 (or /matchup/nba/team1-team2) and have that page show up?

    Thanks again!

    Moderator bcworkz

    (@bcworkz)

    It kind of difficult to talk about matchups without knowing how teams relate to players. For the sake of discussion, lets say they are each their own CPT related through a custom field in player meta data. Also, each team is assigned a league taxonomy term.

    I think matchups can be managed through a custom page template. There is no need for any matchup data object, it’s a virtual construct dynamically created on the fly. There could be a page called “matchup” which is based upon this template. Depending on the amount of data passed in the URL, the page does different things. Requesting the page alone presents a selection box for league. Requesting the page with league selection presents selection boxes for two teams in the league. Requesting page, league, and one team presents a selection box for the other team. Requesting the page with all the pertinent data presents the matchup results.

    You get teams by querying for team CPTs that are assigned the selected league term. You get team players by querying for player CPTs that have the selected team as post meta. The template code can do what ever it does with two teams and their players and spits out the results.

    You can generate a sitemap list of all possible matchups by first getting all league terms, then for each league, query for teams in the league and generate all permutations of the various team matchups. All the URLs lead to the one matchup page, but you could have hundreds of URLs that each have different output.

    HelgaTheViking

    (@helgatheviking)

    My first thought was Posts to Posts but that seems to have been retired. There might be an alternative like Post Connector.

    Thread Starter Phillip Burger

    (@phillipburger)

    @bcworkz – okay, that gets me started. Yes, the concept is only that a matchup is in a league, compares 2 teams (by some sort of league-specific slug), and that both teams must be in the same league. Those are the only requirements, so the search box option may not even be needed…but I see what you mean. Like for brief example, BOS may count for Boston Red Sox if the league is MLB and may count for Boston Celtics if the league is NBA, so kind of a combination of “team slug” and “league”. Thanks for the ideas there!

    @helgatheviking – I will check into that as well, though it may become more than I am looking for since I want to be able to more simply enter all leagues into a category and then create each team to link to a category then player to a category and call out the team…well, maybe at that point of creating the players I can do the related linking. Yeah, I will see how that works.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Input please on tricky use of Custom Post Type and Term Hierarchies?’ is closed to new replies.