How to Speed Up Non-Paginated WordPress WP_Query Loops with no_found_rows

Every time a theme or custom plugin runs new WP_Query() to fetch five related posts, three featured cards, or a navigation menu list, WordPress does extra database work by default: it calculates the total number of matching rows across the entire wp_posts table so it can populate $query->found_posts and $query->max_num_pages for pagination. On a small blog that overhead goes unnoticed, yet on sites with tens of thousands of posts or WooCommerce products, that hidden row-counting query adds up on every uncached page load. Setting 'no_found_rows' => true turns that extra count off when you do not need pagination.

Editorial illustration comparing WordPress WP_Query with and without no_found_rows => true

Editorial illustration: pass 'no_found_rows' => true on fixed-count queries, and leave it false on paginated archives.

Summary

  • By default, WP_Query runs extra counting work (SQL_CALC_FOUND_ROWS / set_found_posts()) to compute total matching rows for pagination.
  • Passing 'no_found_rows' => true skips that total count, letting MySQL/MariaDB stop as soon as it gathers the requested posts_per_page rows.
  • As WordPress VIP’s query optimization guide emphasizes, use 'no_found_rows' => true only on non-paginated queries (related posts, hero sliders, sidebar widgets, REST/AJAX fixed lists).
  • Never enable no_found_rows globally via pre_get_posts on main archive queries, or pagination links (paginate_links(), next_posts_link()) will break.

What no_found_rows actually changes in SQL

When you instantiate new WP_Query( array( 'posts_per_page' => 5 ) ), WordPress assumes you might render “Page 1 of 42” at the bottom of the loop. To know that 42 exists, MySQL cannot simply stop after finding 5 matching rows—it has to count all matching rows in the table (historically using SQL_CALC_FOUND_ROWS followed by SELECT FOUND_ROWS()).

When you add 'no_found_rows' => true:

$related = new WP_Query(
    array(
        'post_type'              => 'post',
        'posts_per_page'         => 5,
        'no_found_rows'          => true,
        'update_post_meta_cache' => false,
        'update_post_term_cache' => false,
    )
);

Notice what happens:

  1. WordPress skips set_found_posts() completely, leaving $related->found_posts at 0 and $related->max_num_pages at 0.
  2. MySQL can honor LIMIT 0, 5 and stop scanning as soon as 5 qualifying rows are found.
  3. If your loop only needs post titles and permalinks (no custom fields or category badges), pairing 'no_found_rows' => true with 'update_post_meta_cache' => false and 'update_post_term_cache' => false avoids extra wp_postmeta and wp_term_relationships priming queries too.

When to use no_found_rows => true (and when not to)

Safe places to enable it

  • Related posts sections below an article (posts_per_page => 3 or 4)
  • Homepage featured blocks or hero carousels showing a fixed number of items
  • Footer or sidebar “Latest News” widgets
  • Existence checks (posts_per_page => 1 just to see if at least one matching post exists)

Places you must leave it false

  • Main blog archive, category, tag, and search loops where paginate_links() or “Next Page” buttons depend on $wp_query->max_num_pages
  • Custom paginated REST endpoints that return X-WP-Total and X-WP-TotalPages headers
  • Infinite scroll / “Load More” grids that calculate whether another page exists from max_num_pages

Step-by-step: Audit custom queries safely

  1. Test on staging first and measure before changing code. Back up your site (see our WordPress backup restore rehearsal) and inspect slow queries on staging using Query Monitor or your host’s slow SQL log.
  2. Search your theme and custom plugins for new WP_Query and get_posts(). Remember that WordPress’s get_posts() helper already sets 'no_found_rows' => true by default under the hood—it is direct new WP_Query() calls that default to false.
  3. Add 'no_found_rows' => true only to fixed-limit loops. Check each template where the query runs to confirm max_num_pages or found_posts is not referenced.
  4. Keep meta/term cache flags accurate. Only set 'update_post_meta_cache' => false if your loop does not call get_post_meta() or ACF’s get_field() inside the while ( $query->have_posts() ) block—otherwise you will accidentally trade one batch query for N+1 individual queries.
  5. Pair query cleanup with broader WordPress performance hygiene. Check WordPress wp_options autoloaded data and non-blocking wp_enqueue_script loading strategies so both database and front-end rendering stay fast.

Common mistakes

  • Applying no_found_rows => true inside pre_get_posts without checking $query->is_main_query(). Even worse, applying it to $query->is_main_query() on /blog/ breaks pagination on page 2 and beyond.
  • Disabling update_post_meta_cache while rendering thumbnails or custom fields. the_post_thumbnail() reads _thumbnail_id post meta; disabling the meta cache while showing featured images forces WordPress to query _thumbnail_id one post at a time.
  • Expecting no_found_rows to fix an unindexed meta_query. Skipping row counting helps, yet a LIKE '%keyword%' search across wp_postmeta will still scan huge tables slowly unless you rethink the data model or add caching.

Why this matters

Small secondary WP_Query blocks often run on every single page view—header menus, sidebars, and footer widgets included. Removing unnecessary total-row counts keeps database CPU steady during traffic spikes without altering what visitors see.

My Take

Whenever you write new WP_Query() for a fixed list of 3 to 10 items, treat 'no_found_rows' => true as part of your standard boilerplate right next to 'posts_per_page'. Just never touch main archive pagination with it, and keep get_posts() in mind when you only need a simple array of WP_Post objects.

Conclusion

Add 'no_found_rows' => true to custom WP_Query loops that do not use pagination, leave update_post_meta_cache enabled if your template renders featured images or custom fields, and verify both SQL query counts and archive pagination on staging before deploying.

Sources