[wp-trac] [WordPress Trac] #52167: WP_Query: always convert `any` post type values to public values.

WordPress Trac noreply at wordpress.org
Thu Dec 24 01:01:27 UTC 2020


#52167: WP_Query: always convert `any` post type values to public values.
---------------------------+-----------------------------
 Reporter:  peterwilsoncc  |      Owner:  (none)
     Type:  enhancement    |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Query          |    Version:
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Instantiating a WP_Query with each of the following parameters will return
 all public post types (post, pages and attachments by default):


 {{{#!php
 <?php
 new WP_Query( [ 'post_type' => 'any' ] );
 new WP_Query( [ 'post_type' => [ 'any' ] ] );
 /*
 WHERE 1=1
   AND wp_posts.post_type IN ('post', 'page', 'attachment')
   AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-
 draft'))
  */
 }}}

 However, manually adding another post type to an array containing `any`
 will result in a query searching for the post types `any` and the
 subsequent post types. This is the case regardless as to whether the
 included types are public or private.

 {{{#!php
 <?php
 new WP_Query( [ 'post_type' => [ 'any', 'post' ] ] );
 /*
 WHERE 1=1
   AND wp_posts.post_type IN ('any', 'post')
   AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-
 draft'))
 */

 new WP_Query( [ 'post_type' => [ 'any', 'revision' ] ] );
 /*
 WHERE 1=1
   AND wp_posts.post_type IN ('any', 'revision')
   AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-
 draft'))
 */
 }}}


 I am writing up some basic tests and create a pull request on GH to
 demonstrate the unexpected queries.

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


More information about the wp-trac mailing list