Created
April 11, 2023 17:46
-
-
Save kadimi/a7771b1154c73b0326f64f995deb186c to your computer and use it in GitHub Desktop.
SportsPress - Get Players by Team
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sp_get_players_by_team($team, $current_or_past_or_all = 'all') | |
{ | |
switch ($current_or_past_or_all) { | |
case 'current': | |
$team_key = 'sp_current_team'; | |
break; | |
case 'past': | |
$team_key = 'sp_past_team'; | |
break; | |
default: | |
$team_key = 'sp_team'; | |
} | |
return get_posts( | |
[ | |
'post_type' => 'sp_player', | |
'posts_per_page' => -1, | |
'meta_key' => 'sp_number', | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'meta_query' => [ | |
[ | |
'key' => $team_key, | |
'value' => $team, | |
], | |
], | |
] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment