$wp_query->post_count = count($wp_query->posts); $wp_query->spoofed = true; $wp_query->rewind_posts(); } } /** * Restore the original query after spoofing it. */ public static function restoreQuery() { global $wp_query; if (isset($wp_query->spoofed) && $wp_query->spoofed) { // take the spoofed post out of the posts array array_pop($wp_query->posts); // fix the post_count $wp_query->post_count = count($wp_query->posts); // rewind the posts $wp_query->rewind_posts(); if ($wp_query->have_posts()) { wp_reset_postdata(); } else { // there are no posts, unset the current post unset($wp_query->post); } // don't do this again unset($wp_query->spoofed); } } } TribeEventsTemplates::init(); }