Week_View::get_next_event_date()

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


Parameters

$current_date

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


Top ↑

Return

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


Top ↑

Source

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

	public function get_next_event_date() {
		$args = $this->filter_repository_args( parent::setup_repository_args( $this->context ) );
		$date         = $this->context->get( 'event_date', 'today' );
		$current_date = Dates::build_date_object( $date );
		list( $week_start ) = $this->calculate_grid_start_end( $current_date );

		// 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 ];
		}

		list( $week_start, $week_end ) = $this->calculate_grid_start_end( $current_date );

		// 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( $week_end->format( 'Y-m-d' ) ) )
			->order( 'ASC' )
			->first();

		if ( ! $next_event instanceof \WP_Post ) {
			return false;
		}

		// At a minimum pick the next week or the week the next event starts.
		$next_date = max(
			Dates::build_date_object( $next_event->dates->start ),
			$current_date->modify( '+1 week' )
		);

		$next_date = $next_date->format( 'W' );

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

		return $next_date;
	}

Top ↑

Changelog

Changelog
Version Description
5.14.2 Introduced.