Month_View::get_next_event_date( TribeEventsViewsV2ViewsDateTime|false $current_date )
Get the date of the event immediately after to the current view date.
Contents
Parameters
- $current_date
-
(TribeEventsViewsV2ViewsDateTime|false) (Required) A DateTime object signifying the current date for the view.
Return
(TribeEventsViewsV2ViewsDateTime|false) Either the next event chronologically, the next month, or false if no next event found.
Source
File: src/Tribe/Views/V2/Views/Month_View.php
public function get_next_event_date( $current_date ) { $args = $this->filter_repository_args( parent::setup_repository_args( $this->context ) ); // Use cache to reduce the performance impact. $cache_key = __METHOD__ . '_' . substr( md5( wp_json_encode( [ $current_date, $args ] ) ), 10 ); if ( isset( $this->cached_event_dates[ $cache_key ] ) ) { return $this->cached_event_dates[ $cache_key ]; } // The first event that ends after the end of the month; it could still begin in this month. $next_event = tribe_events() ->by_args( $this->filter_repository_args( $args ) ) ->where( 'starts_after', tribe_end_of_day( $current_date->format( 'Y-m-t' ) ) ) ->order( 'ASC' ) ->first(); if ( ! $next_event instanceof \WP_Post ) { return false; } // At a minimum pick the next month or the month the next event starts in. $next_date = max( Dates::build_date_object( $next_event->dates->start ), $current_date->modify( '+1 month' ) ); $this->cached_event_dates[ $cache_key ] = $next_date; return $next_date; }
Changelog
Version | Description |
---|---|
5.16.1 | Introduced. |