[wp-hackers] Skip Main Query
Theodor Ramisch
theodor_ramisch at hotmail.com
Sat Jul 31 11:27:10 UTC 2010
Thanks Michael, I will try if that works.
> From: mda at blogwaffe.com
> Date: Sat, 31 Jul 2010 01:18:18 -0700
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] Skip Main Query
>
> 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'
>
> Mike
> --mdawaffe
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list