3

I have a custom post type called Baseball Players which contains teams, positions, and a league taxonomy. A team consists of the team name, logo, description, and coach. A position just consists of the name. A league consists of a name, logo, description. So when you create a new Baseball player custom post type you can assign the team, position, and league for the player.

Now, I'm looking for a way to customize the order players are displayed in each taxonomy. For example, when you view players by team name the order is completely different for each team. It is not by position, league or a specific field. The same is true for position and league. When you view players by league the order of players is different for each league. I don't believe we can implement this through the menu_order field because you would need multiple menu_order fields (one for each team, position, and league for each player). Though this might be the only solution.

Is there a way to handle this unique ordering for each term in the taxonomy? Additionally, is there a way to add multiple custom fields for a taxonomy (ex: team, which contains a team name, logo, description, and coach)?

Let me know if you need me to further explain. Any help is appreciated. Thanks!

2
  • Hi @jaysonp - Nice question writeup but it is unclear is just a few places. For example "when you view players by team name the order is completely different for each team" did you mean "I need to set the view ordering of players differently for each team" or did you mean "when you view players by team name the order is completely different for each team and I need to change it to be ...?" I have the same questions about the rest of the paragraph. (I think you meant the first but I've learned not too assume to much from people's questions.) Sep 26, 2010 at 18:07
  • Hey MikeSchinkel, I'm a little confused by your two options, but I believe it is the first. Let me try to explain this better. In the admin, I will need to be able to control the view ordering of players for each team, each position, and each league. Basically, every possible combination will/could have a unique view ordering. Let's say all the same players on are team A and team B. I'm looking to control the view ordering for both as it will be unique. Additionally, those order of players will be different for league as well. Hopefully that helps. Let me know if it is still unclear.
    – jaysonp
    Sep 26, 2010 at 23:44

1 Answer 1

2

Is there a way to handle this unique ordering for each term in the taxonomy?

You can use custom fields to store the order of the players (e.g.: team_order, league_order, position_order). And dynamically modify the order in your index, archive or taxonomy template file (whatever you use):

if( is_tax(array('team','league','position')) ) {
    if( is_tax('team') {
        $wp_query->set('meta_key', 'team_order');
    } elseif( is_tax('league') {
        $wp_query->set('meta_key', 'league_order');
    } elseif( is_tax('position') {
        $wp_query->set('meta_key', 'position_order');
    }
    $wp_query->set('orderby', 'meta_value');
    $wp_query->get_posts();
}

Additionally, is there a way to add multiple custom fields for a taxonomy (ex: team, which contains a team name, logo, description, and coach)?

No way, out of the box, You can store this in a custom post type or the options table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.