Title: Adding players programmatically &#8211; Doesn&#039;t get added to Player Lists
Last modified: September 1, 2016

---

# Adding players programmatically – Doesn't get added to Player Lists

 *  [clownay](https://wordpress.org/support/users/clownay/)
 * (@clownay)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/)
 * Hi,
 * I’m adding players programmatically via my own plugin.
    They all get their current
   team correctly and I’ve created a relative team playerlist for each team, which
   is set to Auto add players with the same team.
 * The only time when a player gets on that playerlist is when I go into that player
   and hit the “Update” button. I think it seems like something is missing, until
   I hit the update button. But they are created correctly as i see no errors.
 * [https://wordpress.org/plugins/sportspress/](https://wordpress.org/plugins/sportspress/)

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

 *  [Roch](https://wordpress.org/support/users/rochesterj/)
 * (@rochesterj)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-7624820)
 * Hi!
 * I’m suspecting the “auto” option is carried in the wp-admin (so in SportsPress
   when you set to nothing and is creating a post via wp-admin it’ll be added to
   the player list).
 * What you could do to debug is test:
    1) What are the custom fields for a new 
   player via wp-admin X your plugin 2) What happens when you update a player, what
   POST data is being sent
 * Kind Regards,
    -Roch
 *  Thread Starter [clownay](https://wordpress.org/support/users/clownay/)
 * (@clownay)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-7624826)
 * Just to clarify, this is what i do when i add a player via my own plugin
 *     ```
       public function myplugin_add_player($post_data, $player, $team_slug) {
                               $post_id = wp_insert_post($post_data);
       			$player_name_slug = strtolower($player->first_name . '-' . $player->last_name);
       			$player_team_slug_short = substr($team_slug, 4);
   
       			# Set Position
       			wp_set_object_terms($post_id, $player->position_name, 'sp_position', false);
   
       			# Set League
       			wp_set_object_terms($post_id, 'NFL', 'sp_league', false);
   
       			# Set Nationality
       			update_post_meta($post_id, 'sp_nationality', trim(strtolower($player->country)));
   
       			# Set Team And Current Team
       			update_post_meta($post_id, 'sp_current_team', $this->nfl_team_slug[$team_slug]);
   
       			# Set Player Image
       			$this->gulklud_get_player_image($player_team_slug_short, $player_name_slug, $player->name, $post_id);
       }
       ```
   
 *  Thread Starter [clownay](https://wordpress.org/support/users/clownay/)
 * (@clownay)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-7624827)
 * This is the post data being sent when i create one on via wp-admin
 * _wpnonce:f9a2db03c2
    _wp_http_referer:/wp-admin/post-new.php?post_type=sp_player
   user_ID:3 action:editpost originalaction:editpost post_author:3 post_type:sp_player
   original_post_status:auto-draft referredby:[http://nflgeeks.com/wp-admin/admin.php?page=gulklud](http://nflgeeks.com/wp-admin/admin.php?page=gulklud)
   _wp_original_http_referer:[http://nflgeeks.com/wp-admin/admin.php?page=gulklud](http://nflgeeks.com/wp-admin/admin.php?page=gulklud)
   auto_draft: post_ID:10235 meta-box-order-nonce:67011d791a closedpostboxesnonce:
   d8dca0bca2 post_title:Andreas Quist samplepermalinknonce:06103d97ee content: 
   wp-preview: hidden_post_status:draft post_status:draft hidden_post_password: 
   hidden_post_visibility:public visibility:public post_password: mm:08 jj:02 aa:
   2016 hh:07 mn:31 ss:05 hidden_mm:08 cur_mm:08 hidden_jj:02 cur_jj:02 hidden_aa:
   2016 cur_aa:2016 hidden_hh:07 cur_hh:07 hidden_mn:31 cur_mn:31 original_publish:
   Udgiv publish:Udgiv menu_order:0 _um_custom_access_settings:0 _um_accessible:
   0 _um_access_redirect2: _um_access_roles[]:0 _um_access_redirect: um_admin_save_metabox_access_nonce:
   a276ef939f _wp_http_referer:/wp-admin/post-new.php?post_type=sp_player sp_twitter:
   sp_columns[]:0 sp_columns[]:0 sportspress_meta_nonce:39166d70b2 _wp_http_referer:/
   wp-admin/post-new.php?post_type=sp_player sp_number: sp_nationality[]:den tax_input[
   sp_position][]:0 sp_current_team[]:2645 tax_input[sp_league][]:0 tax_input[sp_league][]:
   16 tax_input[sp_season][]:0 sp_metrics[height]: sp_metrics[weight]: excerpt: 
   post_name: post_author_override:3 slide_template:default twitter_custom:4a1ec65607
   _wp_http_referer:/wp-admin/post-new.php?post_type=sp_player twitter_share[text]:
   twitter_share[hashtags]: twitter_card[title]: twitter_card[description]:
 *  Thread Starter [clownay](https://wordpress.org/support/users/clownay/)
 * (@clownay)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-7624914)
 * Roch, you got any idea what is going on?
 *  [Roch](https://wordpress.org/support/users/rochesterj/)
 * (@rochesterj)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-7624942)
 * Hi!
 * Here the ones that I don’t see in your code are
    sp_current_team[]:2645 And tax_input[
   sp_league][]:16
 * You are setting them via the slug in your code, so maybe that is why it isn’t
   working.
 * Have you tried using the ID instead?
 * Kind Regards,
    -Roch
 *  Thread Starter [clownay](https://wordpress.org/support/users/clownay/)
 * (@clownay)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-7624951)
 * I am actually using the ID, nfl_team_slug returns the ID of the team.
 * Is there anyway I can use your CSV importer in my own plugin, to import the players?
   The problem is that I’m getting all the players from a JSON endpoint in my own
   plugin and create the players trough that.
 *  Thread Starter [clownay](https://wordpress.org/support/users/clownay/)
 * (@clownay)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-7624976)
 * Roch, how can i import all my players from JSON endpoint into your custom post
   type? I’ve tried anything possible now or is it even possible to post to the 
   import function you have in your plugin?
 *  [AlexTemina](https://wordpress.org/support/users/alextemina/)
 * (@alextemina)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-8304411)
 * Hi, I’m having exactly the same problem as [@clownay](https://wordpress.org/support/users/clownay/).
   
   I can see inside the player edit that the club is set, but it doesn’t appear 
   in the list of players, and neither in the players list of the team. Im’m setting
   the team with Id and everything, but it seems I’m lacking something else, or 
   there is a meta that I’m not setting regarding clubs.
 *  [AlexTemina](https://wordpress.org/support/users/alextemina/)
 * (@alextemina)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-8304417)
 * Ok, I found the problem.
 * You have to set sp_team like sp_currentteam. Otherwise the system doesn’t know
   it. Then it will appear everywhere correctly.
 * I hope this helps you [@clownay](https://wordpress.org/support/users/clownay/)!

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

The topic ‘Adding players programmatically – Doesn't get added to Player Lists’ 
is closed to new replies.

 * ![](https://ps.w.org/sportspress/assets/icon-256x256.png?rev=1252005)
 * [SportsPress - Sports Club & League Manager](https://wordpress.org/plugins/sportspress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sportspress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sportspress/)
 * [Active Topics](https://wordpress.org/support/plugin/sportspress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sportspress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sportspress/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 9 replies
 * 3 participants
 * Last reply from: [AlexTemina](https://wordpress.org/support/users/alextemina/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/adding-players-programmatically-doesnt-get-added-to-player-lists/#post-8304417)
 * Status: not resolved