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 879bd4a2..a79879f0 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 @@ -29,6 +29,10 @@ class SP_Meta_Box_Table_Details { $date_to = get_post_meta( $post->ID, 'sp_date_to', true ); $date_past = get_post_meta( $post->ID, 'sp_date_past', true ); $date_relative = get_post_meta( $post->ID, 'sp_date_relative', true ); + $event_status = get_post_meta( $post->ID, 'sp_event_status', true ); + if ( empty( $event_status ) ) { + $event_status = array( 'publish', 'future' ); + } ?>
@@ -89,6 +93,11 @@ class SP_Meta_Box_Table_Details { sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) ); } ?> +
+
+ > Published/Played
+ > Scheduled/Future
+
+
+
+
+
+
@@ -1349,6 +1361,8 @@ class SP_AJAX { args.number = $div.find('[name=number]').val(); args.columns = $div.find('[name="columns[]"]:checked').map(function() { return this.value; }).get().join(','); args.show_team_logo = $div.find('[name=show_team_logo]:checked').length; + args.show_published_events = $div.find('[name=show_published_events]:checked').length; + args.show_future_events = $div.find('[name=show_future_events]:checked').length; args.show_full_table_link = $div.find('[name=show_full_table_link]:checked').length; } else if ( 'team_gallery' == type ) { args.title = $div.find('[name=title]').val(); diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php index f9122140..a7d8bdb5 100644 --- a/includes/class-sp-league-table.php +++ b/includes/class-sp-league-table.php @@ -23,6 +23,12 @@ class SP_League_Table extends SP_Secondary_Post { /** @var array Teams to check for tiebreakers. */ public $tiebreakers = array(); + + /** @var int Show Published events. */ + public $show_published_events; + + /** @var int Show Scheduled events. */ + public $show_future_events; /** * Returns formatted data @@ -222,10 +228,40 @@ class SP_League_Table extends SP_Secondary_Post { endif; endforeach; - + + // Get which event status to include + $event_status = get_post_meta( $this->ID, 'sp_event_status', true ); + + if ( empty( $event_status ) ) { + $event_status = array( 'publish', 'future' ); + } + + if ( isset( $this->show_published_events ) ) { // If an attribute was pass through shortcode + if ( $this->show_published_events == '1' ) { + $event_status[] = 'publish'; + }else{ + if ( ( $status_key = array_search( 'publish', $event_status ) ) !== false ) { + unset( $event_status[ $status_key ] ); + } + } + } + + if ( isset( $this->show_future_events ) ) { // If an attribute was pass through shortcode + if ( $this->show_future_events == '1' ) { + $event_status[] = 'future'; + }else{ + if ( ( $status_key = array_search('future', $event_status) ) !== false ) { + unset( $event_status[ $status_key ] ); + } + } + } + + // Make sure to have unique values in the array + $event_status = array_unique( $event_status ); + $args = array( 'post_type' => 'sp_event', - 'post_status' => array( 'publish', 'future' ), + 'post_status' => $event_status, 'numberposts' => -1, 'posts_per_page' => -1, 'orderby' => 'post_date', diff --git a/templates/league-table.php b/templates/league-table.php index 5c35c5ae..529a3afe 100644 --- a/templates/league-table.php +++ b/templates/league-table.php @@ -48,6 +48,13 @@ if ( $show_title && false === $title && $id ): $title = get_the_title( $id ); endif; +//Check if we have event status sent from shortcode +if ( isset( $show_published_events ) ) + $table->show_published_events = $show_published_events ; + +if ( isset( $show_future_events ) ) + $table->show_future_events = $show_future_events ; + //Create a unique identifier based on the current time in microseconds $identifier = uniqid( 'table_' );