Opened 10 years ago
Closed 10 years ago
#28007 closed defect (bug) (fixed)
any post_status blocks others
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
Using WP_Query with a post_status argument array('any', 'trash') does only notice the any, so the corresponding SQL statement does look like:
AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))
And not how expected:
AND (wp_posts.post_status <> 'auto-draft')
Attachments (1)
Change History (4)
#1
@
10 years ago
- Keywords needs-patch needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
#2
@
10 years ago
- Keywords has-patch added; needs-patch needs-unit-tests removed
- Milestone changed from Future Release to 4.0
'post_status' => 'any'
is an alias forget_post_stati( array( 'exclude_from_search' => true ) )
This does not include statuses in the query SQL, it just excludes some statuses.
However, if you pass:
'post_status' => 'any, auto-draft'
or 'post_status' => array( 'any', 'auto-draft' )
... they should be combined. They aren't really combined, what happens: when the 'any' logic is deciding to exclude statuses, it should make sure they aren't also in the passed post_status
array.
I think that this wasn't considered when any
was implemented for post_status
. I wouldn't say this way is suggested, but it also isn't wholly invalid.
zugort, thanks for the report.
'any'
might not have been intended to be used in this context - but, if'any'
doesn't return *every* status, than it is an alias for a subset, so your use case might be valid.This needs patch and unit tests for consideration in the next release. Or at least a patch, and someone else can help with the unit tests.