Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#22001 closed defect (bug) (maybelater)

Handling private and protected posts when querying multiple post types

Reported by: tamlyn Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Query Keywords: has-patch
Focuses: Cc:
PR Number:


When querying multiple post types (e.g. new WP_Query(array('slug'=>$slug, 'post_type'=>'any') the automatic handling of protected and private posts fails because it looks for capabilities 'edit_any' and 'read_any' which don't exist.

The attached patch illustrates the problem with a suggested fix. However it's possible I have misunderstood how this is supposed to work.

Attachments (1)

private_and_protected_posts.patch (1.5 KB) - added by tamlyn 7 years ago.

Download all attachments as: .zip

Change History (5)

#1 @tamlyn
7 years ago

  • Cc tamlyn@… added

#2 @nacin
7 years ago

This is a known thing, really — It deliberately fails because it is not easy to construct sane SQL that will work individually across each post type + post_status pairing, as each post type is pretty much guaranteed to have different capabilities.

So essentially, you won't get back any private or protected posts unless you are querying a particular post type.

All ears on how to make this better.

#3 @SergeyBiryukov
7 years ago

  • Version changed from trunk to 3.4

#4 @wonderboymusic
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

No traction in a year.

Note: See TracTickets for help on using tickets.