Opened 8 months ago

Last modified 8 months ago

#22001 new defect (bug)

Handling private and protected posts when querying multiple post types

Reported by: tamlyn Owned by:
Priority: normal Milestone: Awaiting Review
Component: Query Version: 3.4
Severity: normal Keywords: has-patch
Cc: tamlyn@…

Description

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 8 months ago.

Download all attachments as: .zip

Change History (4)

  • Cc tamlyn@… added

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.

  • Version changed from trunk to 3.4
Note: See TracTickets for help on using tickets.