Get the team ID
-
I’m trying to identify the team ID for a player in a season and a league.
I’m creating a player object with the player ID.
With the data() method of this player, I can retreive all seasons he have played.
within each season, I can find the team’s name he was part of.
After that, I’m using a get_post with the team name to query a team from the database and get the ID with that query.Here is my code:
// Create a player object with a $player_ID
$player = new SP_Player( $player_id );
// Get player data for a specific league
$playerdata = $player->data($league_id,false,-1);
//Get the team name he played that season in that league
$team_name = $playerdata[$season_id][‘team’];
//query the database for the team having the team name previously determined
$args = array(
‘post_type’ => ‘sp_team’,
‘numberposts’ => -1,
‘posts_per_page’ => -1,
‘title’=>$team_name
);
//get the team ID of the team founded
$teamID = get_posts($args)[0]->ID;`It seams a lot of code simply to get the team ID of the team a player was member of, for a season in a league.
Is there a better way to retreive this information ?
Thanks
The topic ‘Get the team ID’ is closed to new replies.