• I am using the latest version of WordPress with the latest version of SportsPress.

    I am uploading a new season of players (over 400). I want to enable Player Performance and Player Statics on all players.

    Going through each player 1-by-1 is way to time consuming. Is there a way to upload with these stats enabled, or to bulk enable them?

    I searched for this issue and only found 1 thread over a year ago that said it may be in v1.6.

    Thanks.

    https://www.ads-software.com/plugins/sportspress/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi!

    We do have a csv import tool, but I’m not sure how you could use it for this kind of data as it’s most used for matches and competitions data.

    Kind Regards,
    -Roch

    Thread Starter ChaosZero112

    (@chaoszero112)

    Thank you for your reply Roch,

    Ignoring the upload portion, the main request/inquiry I have is how do I activate Player Performance and Player Statistics on All player pages at once?

    Hi!

    I’m not sure if I get what you mean. Activate? How so?

    Kind Regards,
    -Roch

    Thread Starter ChaosZero112

    (@chaoszero112)

    Sorry for my lack of clarity Roch.

    When a new player is created, Statistics are not shown on their page by default. They must be manually selected from the Player Performance and Player Statistics check boxes under the Columns heading, and a team selected.

    Example:
    https://i.imgur.com/4XDhw8v.jpg”

    I want Statistics turned on for all players.

    Example:
    https://i.imgur.com/0FIepsZ.jpg

    I have close to 500 players. It would be insane to have to go to each player 1-by-1 to show these stats.

    Is there a bulk update feature that can enable statistics on all player pages?

    i’d also be interested in this.

    Hi!

    Thanks for the screenshots, I see what you mean now. That is a great idea actually, but I’ll send this to our dev team to see if they have any ideas on how to do that (maybe a SQL command to update all players at once).

    Please stand by!

    Kind Regards,
    -Roch

    Plugin Author Brian

    (@brianmiyaji)

    You might be able to do this via a custom script to get all posts then update the sp_columns post meta. Here’s some temporary code you could add to your theme’s functions.php to make this happen:

    function my_custom_sportspress_player_columns() {
    	$columns = array( 'team', 'goals', 'assists', 'yellowcards', 'redcards' ); // Add the variable names (slugs) to this array
    
    	$args = array(
    		'post_type' => 'sp_player',
    		'posts_per_page' => -1,
    		'fields' => 'ids'
    	);
    	$players = get_posts( $args );
    
    	if ( ! is_array( $players ) ) return;
    
    	foreach ( $players as $player ) {
    		update_post_meta( $player, 'sp_columns', $columns );
    	}
    }
    add_action( 'admin_init', 'my_custom_sportspress_player_columns' );

    Edit the 2nd line to include the variable names (slugs) of the columns you want to turn on for all players, for example:

    $columns = array( 'team', 'g', 'a', 'pim', 'p', 'gp' );

    You can verify the slugs by going to SportsPress > Configure.

    Once you’ve added this code to the bottom of your active theme’s functions.php, load the admin page once. The script will run each time you load the admin, so be careful ??

    After the admin loads, delete the code. The changes should be applied to every player now. Depending on the number of players, there is a chance that this could time out. If this happens, we’ll need to tweak the code.

    Let me know if that works! This would probably be much easier as a global setting, so I’ve added it to our roadmap for the next major update ??

    Thread Starter ChaosZero112

    (@chaoszero112)

    Hi Brian,

    Thank you for the script. It seems the code did work 90% of what I needed.

    Unfortunately it didn’t activate the Team or the Season.

    https://i.imgur.com/DjKrwlV.png

    Which looks like the script wasn’t written to do.

    If I could get those last 2 things activated, it would be awesome.

    Did you get this worked out with the team and season added too. I have 2300 members so even bigger job to do manually.

    Thread Starter ChaosZero112

    (@chaoszero112)

    I still need the above as well.

    Plugin Author Brian

    (@brianmiyaji)

    Alright, let’s try this:

    function my_custom_sportspress_player_columns() {
    	$columns = array( 'team', 'goals', 'assists', 'yellowcards', 'redcards' ); // Add the variable names (slugs) to this array
    
    	$args = array(
    		'post_type' => 'sp_player',
    		'posts_per_page' => -1,
    		'fields' => 'ids'
    	);
    	$players = get_posts( $args );
    
    	if ( ! is_array( $players ) ) return;
    
    	foreach ( $players as $player ) {
    		$teams = get_post_meta( $player, 'sp_team', false );
    		$league_terms = get_the_terms( $player, 'sp_league' );
    		$season_terms = get_the_terms( $player, 'sp_season' );
    		$leagues = array();
    		if ( is_array( $league_terms ) && is_array( $season_terms ) ) {
    			foreach ( $league_terms as $league_term ) {
    				if ( 0 == $league_term->term_id ) continue;
    				foreach ( $season_terms as $season_term ) {
    					$leagues[ $league_term->term_id ][ $season_term->term_id ] = sp_array_value( $teams, 0, '-1' );
    				}
    			}
    		}
    		update_post_meta( $player, 'sp_leagues', $leagues );
    		update_post_meta( $player, 'sp_columns', $columns );
    	}
    }
    add_action( 'admin_init', 'my_custom_sportspress_player_columns' );
    Thread Starter ChaosZero112

    (@chaoszero112)

    Thanks Brian,

    Very close! The Team was activated, however Career Total remained unselected (although again looks like the script wasn’t written to activate it).

    View post on imgur.com

    Also, it never added Past Teams. However, I realize this one is probably impossible to automate, as you wouldn’t know which Season was which Team without intervention. So it’s just a heads up, and nothing that needs to be fixed. As long as the next time you use this script, it doesn’t change values already in place (eg it should only change the “- NONE -” value).

    View post on imgur.com

    When you visited this player’s page, it said she played in Spartans both S2016 and W2015-2016, despite Current Team being Spartans and Past Team being Willow Salon (Leafs).

    Big question then is will this be integrated in an upcoming update? Our season switch begins on Monday, I would love to have a built in update button this.

    Plugin Author Brian

    (@brianmiyaji)

    Ah, this script would require that the teams are already selected for that player. It then selected that team from each season’s dropdown and saves the table.

    Would it help to have a bulk edit feature where you could select multiple players and choose current and past teams?

    Thread Starter ChaosZero112

    (@chaoszero112)

    A Bulk edit feature would make things a bit easier, yes, as usually our players change teams between seasons. A handful remain the same.

    Sorry to resurrect a potentially dead thread, but the above code really helped me too. As with @chaoszero112, the ability to activate seasons in the Career Total table would make this code absolutely complete for what I need it for. @brianmiyaji, you seem to be the hero we need, is there anything you can append to the existing script to make this happen?

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Enable Stats for All Players’ is closed to new replies.