Page::restore_main_query()

Restored the Hijacked posts from the main query so that we can run the template method properly with a fully populated WP_Query object.


Return #

(void) Action hook with no return.


Top ↑

Source #

File: src/Tribe/Views/V2/Template/Page.php

	public function restore_main_query() {
		// If the query doesnt have hijacked posts.
		if ( ! $this->has_hijacked_posts() ) {
			return;
		}

		$wp_query = tribe_get_global_query_object();

		if ( ! $wp_query instanceof WP_Query ) {
			return;
		}

		$wp_query->posts = $this->get_hijacked_posts();
		$wp_query->post_count = count( $wp_query->posts );

		// If we have other posts besides the spoof, rewind and reset.
		if ( $wp_query->post_count > 0 ) {
			$wp_query->post = reset( $wp_query->posts );
			$wp_query->rewind_posts();
			wp_reset_postdata();
		}
		// If there are no other posts, unset the $post property.
		elseif ( 0 === $wp_query->post_count ) {
			$wp_query->current_post = -1;
			$wp_query->post = null;
		}

		$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'] = $wp_query;
	}

Top ↑

Changelog #

Changelog
Version Description
4.9.2 Introduced.