[wp-trac] [WordPress Trac] #60468: WP_Query matches any post when query parameter "name" is an empty string

WordPress Trac noreply at wordpress.org
Wed Feb 7 17:25:07 UTC 2024


#60468: WP_Query matches any post when query parameter "name" is an empty string
--------------------------+-----------------------------
 Reporter:  miyarakira    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 `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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60468>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list