Skip to content

Instantly share code, notes, and snippets.

@kadimi
Created April 11, 2023 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadimi/a7771b1154c73b0326f64f995deb186c to your computer and use it in GitHub Desktop.
Save kadimi/a7771b1154c73b0326f64f995deb186c to your computer and use it in GitHub Desktop.
SportsPress - Get Players by Team
<?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