[wp-hackers] Avoid query_post on frontpage on wp initialization
Sergey Biryukov
sergeybiryukov.ru at gmail.com
Mon Dec 27 22:29:46 UTC 2010
On Tue, Dec 28, 2010 at 12:07 AM, Martin Widmann
<widmann.martin at gmail.com> wrote:
> we are running on a pretty big WP database with a very large posts table with ~500k entries in the posts table. When going to the front page of the blog a query to the wp_posts table is made during WP initialization. This default query on the big table takes ~1sec. The data returned by this query is not required afterwards, so I'd like to avoid doing it.
>
> In wp->main() the query_posts() is always executed and I don't seem to have very much control of what is queried in there. I'd like to avoid querying anything at this stage at all. Later on in the page flow I'll query the database differently. Any idea?
I was able to cancel the initial query with this code in the active
theme's functions.php file:
function cancel_first_query() {
remove_filter('posts_request', 'cancel_first_query');
return '';
}
add_filter('posts_request', 'cancel_first_query');
Sergey
More information about the wp-hackers
mailing list