Optimize WP_Query

Optimize WP_Query

Every time you run query_posts() or create a new WP_Query() (secondary loop), four queries are run:

  1. Getting the posts according to your query string
  2. Calculating how many posts exist for this query (to create pagination)
  3. Loading all metadata for the posts
  4. Loading all taxonomy term information for the posts
  5. 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

date 01. Jan 0001 | modified 28. May 2021
filename: Wordpress - Optimize WP_Query
Article Content