[wp-trac] [WordPress Trac] #51094: WP_Query.query with invalid post_status will return all

WordPress Trac noreply at wordpress.org
Fri Aug 21 12:18:59 UTC 2020


#51094: WP_Query.query with invalid post_status will return all
--------------------------+-----------------------------
 Reporter:  carsonreinke  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  trunk
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hello, I noticed an issue with WooCommerce method {{{ wc_get_products }}}
 and dove into the issue.

 The problem was {{{ wc_get_products(array('status' => 'published')); }}}
 would return **ALL** posts, even trashed ones because of the "published"
 status is not a valid post status.

 I believe that behavior is unexpected that it should return **NO** posts.

 The issue appears to be this portion of {{{WP_Query.get_posts}}} that only
 known post statuses are added to the query:

 {{{#!php
 <?php
                                 foreach ( get_post_stati() as $status ) {
                                         if ( in_array( $status, $q_status,
 true ) ) {
                                                 if ( 'private' === $status
 ) {
                                                         $p_status[] =
 "{$wpdb->posts}.post_status = '$status'";
                                                 } else {
                                                         $r_status[] =
 "{$wpdb->posts}.post_status = '$status'";
                                                 }
                                         }
                                 }
 }}}

 I believe it would best if this method checks for any unrequested post
 status supplied in the query and either applies them to the query or
 produces an error.  I would imagine this is a pretty major change.

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


More information about the wp-trac mailing list