From bc89cc79624d80cddf8e0edee5f541e54dc75c19 Mon Sep 17 00:00:00 2001 From: Nabil Kadimi Date: Wed, 4 Mar 2020 15:44:08 +0100 Subject: [PATCH] Exclude postponed/cancelled events from countdowns (+filter hook) --- templates/countdown.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/templates/countdown.php b/templates/countdown.php index 244d77ec..0dc412b3 100644 --- a/templates/countdown.php +++ b/templates/countdown.php @@ -30,10 +30,22 @@ elseif ( $calendar ): if ( $team ) $calendar->team = $team; $calendar->status = 'future'; - $calendar->number = 1; $calendar->order = 'ASC'; $data = $calendar->data(); - $post = array_shift( $data ); + + /** + * Exclude postponed or cancelled events. + */ + $excluded_statuses = apply_filters( 'sp_countdown_excluded_statuses', array( + 'postponed', + 'cancelled', + ) ); + while ( $post = array_shift( $data ) ) { + $sp_status = get_post_meta($post->ID, 'sp_status', true); + if( ! in_array( $sp_status, $excluded_statuses ) ) { + break; + } + } else: $args = array(); if ( isset( $team ) ) { @@ -61,6 +73,19 @@ else: ); } } + + /** + * Exclude postponed or cancelled events. + */ + $args['meta_query'][] = [ + 'key' => 'sp_status', + 'compare' => 'NOT IN', + 'value' => apply_filters( 'sp_countdown_excluded_statuses', array( + 'postponed', + 'cancelled', + ) ), + ]; + $post = sp_get_next_event( $args ); endif;