[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 Jun 17 18:45:00 UTC 2014
#28568: Can't get private posts/pages via WP_Query when not logged in as
administrator
--------------------------+-----------------------------
Reporter: mklusak | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.9
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
I want to use WP_Query to display content of one private page on some
place in a template.
{{{
// ... theme template sidebar.php, for example
<?php
$the_query = new WP_Query( array( 'page_id' => 25, 'post_status' =>
'private' )); // page #25 is set to "private"
if ($the_query->have_posts())
{
// ... nope, no posts for you today
while ($the_query->have_posts())
{
$the_query->the_post();
the_content();
}
wp_reset_postdata();
}
?>
}}}
But it only works when I am logged in as administrator.
When I am not logged in, and print_r() the $the_query, there is "request"
index filled with:
{{{SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.ID = 25 AND
wp_posts.post_type = 'page' AND ((wp_posts.post_status = 'private'))
ORDER BY wp_posts.post_date DESC}}}
Querying database with it directly in PHPMyAdmin, it returns one row as
expected (page ID 25 row). But template loop does not anything. "Posts"
index in $the_query is empty.
I have expected WP_Query works like "just give me anything I want (defined
by the arguments)" ... and I want page with ID 25.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28568>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list