Tribe__Events__Pro__Main::pre_get_posts( WP_Query $query )

Add custom query modification to the pre_get_posts hook as necessary for PRO.


Parameters

$query

(WP_Query) (Required) The current query object.


Top ↑

Return

(WP_Query) The modified query object.


Top ↑

Source

File: src/Tribe/Main.php

		public function pre_get_posts( $query ) {
			if ( $query->is_single() && $query->get( 'eventDate' ) ) {
				$this->set_post_id_for_recurring_event_query( $query );
			}

			$recurrence_query = null;

			if ( ! empty( $query->tribe_is_event_pro_query ) ) {
				switch ( $query->query_vars['eventDisplay'] ) {
					case 'week':

						$start_date = tribe_get_first_week_day( $query->get( 'eventDate' ) );
						$end_date   = tribe_get_last_week_day( $start_date );

						// if the setting to hide weekends is true
						if ( tribe_get_option( 'week_view_hide_weekends', false ) == true ) {
							$start_of_week = get_option( 'start_of_week' );
							// check if the week is set to start on a weekend day
							// If so, start on the next weekday.
							// 0 = Sunday, 6 = Saturday
							if ( $start_of_week == 0 || $start_of_week == 6 ) {
								$start_date = date( Tribe__Date_Utils::DBDATEFORMAT, strtotime( $start_date . ' +1 Weekday' ) );
							}
							// If the week starts on saturday or friday
							// sunday and/or saturday would be on the other end, so we need to end the previous weekday
							// 5 = Friday, 6 = Saturday
							if ( $start_of_week == 5 || $start_of_week == 6 ) {
								$end_date = date( Tribe__Date_Utils::DBDATEFORMAT, strtotime( $end_date . ' -1 Weekday' ) );
							}
						}

						// if the setting to hide weekends is on
						// need to filter the query
						// need to only show 5 days on the week view

						// if we're using an non-default hour range on week view
						if ( has_filter( 'tribe_events_week_get_hours' ) ) {
							$start_date .= ' ' . tribe_events_week_get_hours( 'first-hour' );
							$end_date .= ' ' . tribe_events_week_get_hours( 'last-hour' );
						}

						$query->set( 'eventDate', $start_date  );
						$query->set( 'start_date', $start_date );
						$query->set( 'end_date', $end_date );
						$query->set( 'posts_per_page', -1 ); // show ALL week posts
						$query->set( 'hide_upcoming', false );
						break;
					case 'photo':
						$query->set( 'hide_upcoming', false );
						break;
					case 'all':
						$recurrence_query = new Tribe__Events__Pro__Recurrence__Event_Query( $query );
						$recurrence_query->hook();
						break;
				}

				/**
				 * Hooks into our query and recurrence query objects after we have done the setup.
				 *
				 * @param WP_Query                                         $query            Query object.
				 * @param null|Tribe__Events__Pro__Recurrence__Event_Query $recurrence_query Recurrence event query object (for `all` view).
				 *
				 * @since 4.7
				 */
				do_action( 'tribe_events_pro_pre_get_posts', $query, $recurrence_query );
			}
		}