diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index 67176d65..cd43efa3 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -466,8 +466,9 @@ jQuery(document).ready(function($){ $(".post-type-sp_list #post-formats-select input.post-format").trigger("change"); // Auto-select hides options - $(".sp-select-setting").change(function() { - $(".sp-select-options").toggle("manual"==$(this).val()); + $(".sp-select-setting").find("select").change(function() { + $(".sp-select-all-range").toggle("manual"==$(this).val()); + $(this).closest(".sp-select-setting").siblings(".sp-tab-select").find("select").change() }); // Configure primary result option (Ajax) diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php index 7d405c4b..ff53b825 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-details.php @@ -22,6 +22,11 @@ class SP_Meta_Box_Table_Details { wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' ); $league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 ); $season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 ); + $select = get_post_meta( $post->ID, 'sp_select', true ); + if ( ! $select ) { + global $pagenow; + $select = ( 'post-new.php' ? 'auto' : 'manual' ); + } ?>

@@ -55,8 +60,14 @@ class SP_Meta_Box_Table_Details { ?>

+

+ +

ID, 'sp_team', 'block', array( 'sp_league', 'sp_season' ) ); + sp_post_checklist( $post->ID, 'sp_team', ( 'auto' == $select ? 'none' : 'block' ), array( 'sp_league', 'sp_season' ) ); sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); ?>
@@ -69,6 +80,7 @@ class SP_Meta_Box_Table_Details { public static function save( $post_id, $post ) { wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' ); wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' ); + update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); } } \ No newline at end of file diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php index 8f5eb842..6f061366 100644 --- a/includes/class-sp-league-table.php +++ b/includes/class-sp-league-table.php @@ -31,10 +31,10 @@ class SP_League_Table extends SP_Custom_Post{ public function data( $admin = false ) { $league_id = sp_get_the_term_id( $this->ID, 'sp_league', 0 ); $div_id = sp_get_the_term_id( $this->ID, 'sp_season', 0 ); - $team_ids = (array)get_post_meta( $this->ID, 'sp_team', false ); $table_stats = (array)get_post_meta( $this->ID, 'sp_teams', true ); $usecolumns = get_post_meta( $this->ID, 'sp_columns', true ); $adjustments = get_post_meta( $this->ID, 'sp_adjustments', true ); + $select = get_post_meta( $this->ID, 'sp_select', true ); // Get labels from result variables $result_labels = (array)sp_get_var_labels( 'sp_result' ); @@ -42,6 +42,47 @@ class SP_League_Table extends SP_Custom_Post{ // Get labels from outcome variables $outcome_labels = (array)sp_get_var_labels( 'sp_outcome' ); + // Get teams automatically if set to auto + if ( 'auto' == $select ) { + $team_ids = array(); + + $args = array( + 'post_type' => 'sp_team', + '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; + + $teams = get_posts( $args ); + + if ( $teams && is_array( $teams ) ) { + foreach ( $teams as $team ) { + $team_ids[] = $team->ID; + } + } + } else { + $team_ids = (array)get_post_meta( $this->ID, 'sp_team', false ); + } + // Get all leagues populated with stats where available $tempdata = sp_array_combine( $team_ids, $table_stats );