Optimize WP_Query
Every time you run query_posts() or create a new WP_Query() (secondary loop), four queries are run:
- Getting the posts according to your query string
- Calculating how many posts exist for this query (to create pagination)
- Loading all metadata for the posts
- Loading all taxonomy term information for the posts
- It is possible to turn off queries 2-4 to increase performance, like this:
XX
$my_query = new WP_Query(array(
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false
));
Andrew Nacin: WP_Query / WordPress In-depth - summary and highlights - Useful Snippets