Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#28007 closed defect (bug) (fixed)

any post_status blocks others

Reported by: zugort's profile zugort Owned by: wonderboymusic's profile wonderboymusic
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)

28007.diff (2.0 KB) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (4)

#1 @wonderboymusic
9 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

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.

#2 @wonderboymusic
9 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.

@wonderboymusic
9 years ago

#3 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28622:

If post_status is passed to WP_Query as an array containing 'any' and anything else, don't exclude the other values if they match when running any's exclusion logic.

Adds unit tests.

Fixes #28007.

Note: See TracTickets for help on using tickets.