Ensure 'found_posts' is correct when no limit queries are in use #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, if a no limit query is set for WP_Query, the returned
'found_posts'
property is zero instead of the number of posts.'found_posts'
is set to 'NA' here:advanced-post-cache/advanced-post-cache.php
Lines 200 to 201 in c46b2d9
And never redeclared.
So when
advanced-post-cache
gets to returning the found posts count:advanced-post-cache/advanced-post-cache.php
Lines 230 to 231 in c46b2d9
It returns 0 because of
(int) 'NA'
.This PR fixes this by returning the count of the cached post IDs if
'found_posts'
is a no limit query ('NA'
). This is important for plugins doing checks against'found_posts'
and are anticipating a non-zero count. For example, bbPress does such a check here: https://github.com/bbpress/bbPress/blob/b772b4503991e3d55a34a4683a1f84e60decbce1/src/includes/replies/template.php#L212-L213This addresses #4.