Opened 2 years ago
#60468 new defect (bug)
WP_Query matches any post when query parameter "name" is an empty string
| Reported by: | miyarakira | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | |
| Severity: | minor | Keywords: | |
| Cc: | Focuses: |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)