Opened 10 months ago
#60468 new defect (bug)
WP_Query matches any post when query parameter "name" is an empty string
Reported by: | miyarakira | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | minor | Version: | |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
WP_Query
matches any post when query parameter name
is an empty string.
For example:
$query = new WP_Query([ 'name' => '', 'post_type' => 'post', 'posts_per_page' => 1, ]); var_dump($query->posts);
The same is true for get_posts()
which uses WP_Query
internally.
This might be the intended behavior, but it's unintuitive and surprising. It can (did) cause a bug in user code that expects such a query to return no results.
Note: See
TracTickets for help on using
tickets.