WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#18284 closed enhancement (worksforme)

Introduce 'post_status' => 'publish_or_private'

Reported by: scribu Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

Description

This code:

$query = new WP_Query();

print_r( $query->posts );

will contain private posts, if the user has the appropriate capabilities.

This code:

$posts = get_posts();
print_r( $posts );

won't contain private posts.

That's because get_posts() always sets 'post_status' to 'publish', for back-compat.

Therefore, I propose we introduce an explicit 'publish_or_private' value, which would allow this:

$posts = get_posts( array( 'post_status' => 'publish_or_private' ) );

Change History (4)

comment:1 nacin3 years ago

array( 'publish', 'private' )?

comment:2 scribu3 years ago

Nope, that won't do because it doesn't check the appropriate user cap.

comment:3 nacin3 years ago

So you're looking for 'post_status' => array( 'publish', 'private' ), 'perm' => 'readable' then.

comment:4 scribu3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.