Day_View::get_next_event_date( TribeEventsViewsV2ViewsDateTime|false $current_date )

Get the date of the event immediately after to the current view date.


Parameters #

$current_date

(TribeEventsViewsV2ViewsDateTime|false) (Required) A DateTime object signifying the current date for the view.


Top ↑

Return #

(TribeEventsViewsV2ViewsDateTime|false) Either the next event chronologically, the next month, or false if no next event found.


Top ↑

Source #

File: src/Tribe/Views/V2/Views/Day_View.php

	public function get_next_event_date( $current_date ) {
		$context = $this->context instanceof Tribe__Context ? $this->context : null;
		$args = $this->filter_repository_args( $this->setup_repository_args( $context ) );
		// This value will mess up our query.
		unset( $args['date_overlaps'] );

		// 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( $args )
			->where( 'starts_after', tribe_end_of_day( $current_date->format( 'Y-m-d' ) ) )
			->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->add( new \DateInterval( 'P1D' ) )
		);

		$this->cached_event_dates[ $cache_key ] = $next_date;

		return $next_date;
	}

Top ↑

Changelog #

Changelog
Version Description
5.16.1 Introduced.