REST API: Avoid duplicated query in post collections.

Avoid duplicated query when retrieving empty posts collections by adding a check if the page is more than 1. 

Props furi3r, gdetassigny, TimothyBlynJacobs, spacedmonkey. 
Fixes #55677.



git-svn-id: https://develop.svn.wordpress.org/trunk@53498 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2022-06-14 12:40:29 +00:00
parent a067d588c3
commit 219927c11b
3 changed files with 64 additions and 7 deletions
@@ -388,7 +388,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
$page = (int) $query_args['paged'];
$total_posts = $posts_query->found_posts;
if ( $total_posts < 1 ) {
if ( $total_posts < 1 && $page > 1 ) {
// Out-of-bounds, run the query again without LIMIT for total count.
unset( $query_args['paged'] );