Ensure array query parameters do not contain empty items #2462
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.
Description of the Change
In some cases query args like
post__in
that are expected to be array might contain invalid data such as an empty string. An array like[ '' ]
will not appear as empty when checked withempty( [ '' ] )
so this update ensures the arrays only contain real values. Database IDs all start from 1 so removing0
is ok here.This issue was observed with Yoast SEO adding subqueries for indexables to populate
post__in
parameters, however the index was incomplete. Can also happens in non-production environments where indexables aren't saved to the database.Alternate Designs
Benefits
Prevents ES query errors such as this one:
Note this part:
Possible Drawbacks
Verification Process
I added this code to as a
mu-plugin
reproduce the WP Query args as a minimal test case:Observe running a search query yields no results (or falls back to a db query).
The change is intentionally light in terms of sanitisation and I haven observed no regressions with valid values for the listed query arguments, even if provided as strings e.g.
(array) "some string" -> [ "some string" ]
.Checklist:
Applicable Issues
Changelog Entry