[wp-trac] [WordPress Trac] #28568: Can't get private posts/pages via WP_Query when not logged in as administrator

WordPress Trac noreply at wordpress.org
Tue Mar 12 15:21:21 UTC 2019


#28568: Can't get private posts/pages via WP_Query when not logged in as
administrator
--------------------------+-----------------------
 Reporter:  mklusak       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:
Component:  Query         |     Version:  3.9
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+-----------------------

Comment (by stracker.phil):

 I agree with @dnaber-de and @mklusak:

 There's an inconsistency between `get_post()` and `get_posts()` which is
 confusing:

 {{{
 $private_id = 123;
 $item1 = get_post( $private_id );
 $item2 = get_posts( [ 'p' => $private_id, 'post_type' => 'page' ] );

 // $item1 is a WP_Post object of the private post. The private-state is
 not checked here.
 // $item2 is an empty array, because I am not logged in.
 }}}

 There should be a new option for get_posts like `ignore_private => true`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/28568#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list