[wp-hackers] Skip Main Query

Michael D Adams mda at blogwaffe.com
Sat Jul 31 08:18:18 UTC 2010

On Fri, Jul 30, 2010 at 3:54 PM, Theodor Ramisch
<theodor_ramisch at hotmail.com> wrote:
> No I've noticed that WordPress still queries the posts from the start page. Is there a way to avoid that?

The following plugin works for me in WP 3.0.

Plugin Name: Kill Front Page Query

function kill_front_page_query() {
	add_filter( 'posts_request', 'kill_one_posts_request', 1000, 2 );

// apply_filters_ref_array() is a beautiful thing
function kill_one_posts_request( $sql, &$query ) {
	// The main query is running on the front page
	// And the currently running query is that main query
	if ( is_front_page() && $query->is_home &&
$GLOBALS['wp_the_query']->is_home ) {
		// We only want to do this once: remove the filter
		remove_filter( 'posts_request', 'kill_one_posts_request', 1000 );
		// Kill the FOUND_ROWS() query too
		$query->query_vars['no_found_rows'] = true;
		return ''; // Kill the query
	return $sql;

add_filter( 'parse_request', 'kill_front_page_query' );

On the front page of a site with no fancy nav menu, I get one query
when viewing it logged out:

SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'


More information about the wp-hackers mailing list