Opened 4 years ago
Last modified 4 years ago
#52167 new enhancement
WP_Query: always convert `any` post type values to public values.
Reported by: | peterwilsoncc | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Instantiating a WP_Query with each of the following parameters will return all public post types (post, pages and attachments by default):
<?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 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.
Change History (1)
This ticket was mentioned in PR #840 on WordPress/wordpress-develop by peterwilsoncc.
4 years ago
#1
- Keywords has-patch has-unit-tests added
Note: See
TracTickets for help on using
tickets.
https://core.trac.wordpress.org/ticket/52167