• Resolved pierrefo

    (@pierrefo)


    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Savvas

    (@savvasha)

    Hi @pierrefo ,

    If the player’s assignments were made correctly there should be an sp-assignments post meta with the format league_season_team bind with your player. You can query for a meta league_season_% and extract the last part which is the team’s id for this specific league and season.

    Thanks,
    Savva

    Thread Starter pierrefo

    (@pierrefo)

    Ho yeah !

    It is so much easier.

    $player_assignments = get_post_meta( $player_id, ‘sp_assignments’, false );

    I only have to get the right league – season combination to get the team_id.

    Thanks

    Roch

    (@rochesterj)

    Hi there!

    Thanks for your reply.

    Is everything resolved then? Let us know if you need anything else

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Get the team ID’ is closed to new replies.