diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php
index e8126b23..ef43bfda 100644
--- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php
+++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php
@@ -25,6 +25,8 @@ class SP_Meta_Box_List_Details {
$grouping = get_post_meta( $post->ID, 'sp_grouping', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
+ $select = get_post_meta( $post->ID, 'sp_select', true );
+ if ( ! $select ) $select = 'auto';
?>
@@ -103,10 +105,18 @@ class SP_Meta_Box_List_Details {
- ID, 'sp_player', 'block', array( 'sp_league', 'sp_season', 'sp_current_team' ) );
- sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
- ?>
+
+
+
+
+ ID, 'sp_player', 'block', array( 'sp_league', 'sp_season', 'sp_current_team' ) );
+ sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
+ ?>
+
ID, 'sp_league', 0 );
$div_id = sp_get_the_term_id( $this->ID, 'sp_season', 0 );
- $player_ids = (array)get_post_meta( $this->ID, 'sp_player', false );
+ $team = get_post_meta( $this->ID, 'sp_team', true );
$list_stats = (array)get_post_meta( $this->ID, 'sp_players', true );
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
$orderby = get_post_meta( $this->ID, 'sp_orderby', true );
$order = get_post_meta( $this->ID, 'sp_order', true );
+ $select = get_post_meta( $this->ID, 'sp_select', true );
// Get labels from performance variables
$performance_labels = (array)sp_get_var_labels( 'sp_performance' );
@@ -49,6 +50,56 @@ class SP_Player_List extends SP_Custom_Post {
// Get labels from outcome variables
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
+ // Get players automatically if set to auto
+ if ( 'auto' == $select ) {
+ $player_ids = array();
+
+ $args = array(
+ 'post_type' => 'sp_player',
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'order' => 'ASC',
+ 'tax_query' => array(
+ 'relation' => 'AND',
+ ),
+ );
+
+ if ( $league_id ):
+ $args['tax_query'][] = array(
+ 'taxonomy' => 'sp_league',
+ 'field' => 'id',
+ 'terms' => $league_id
+ );
+ endif;
+
+ if ( $div_id ):
+ $args['tax_query'][] = array(
+ 'taxonomy' => 'sp_season',
+ 'field' => 'id',
+ 'terms' => $div_id
+ );
+ endif;
+
+ if ( $team ):
+ $args['meta_query'] = array(
+ array(
+ 'key' => 'sp_team',
+ 'value' => $team
+ ),
+ );
+ endif;
+
+ $players = get_posts( $args );
+
+ if ( $players && is_array( $players ) ) {
+ foreach ( $players as $player ) {
+ $player_ids[] = $player->ID;
+ }
+ }
+ } else {
+ $player_ids = (array)get_post_meta( $this->ID, 'sp_player', false );
+ }
+
// Get all leagues populated with stats where available
$tempdata = sp_array_combine( $player_ids, $list_stats );
@@ -129,7 +180,7 @@ class SP_Player_List extends SP_Custom_Post {
);
endif;
- if ( $league_id ):
+ if ( $div_id ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',