Sorting for each custom taxonomy

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.

Read More

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!

Related posts

Leave a Reply

1 comment

  1. 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.