0

Hidden private posts for not logged in users

The private posts are by default only visible when logged in.

Override, show private posts for everyone

Is there a clever way to override this? Make it visible to everyone?

404 page

I know about using it in queries but the big problem is the 404 page that is shown. Instead of 404 template it should use single.php template.

2
  • possible duplicate of Prevent private post 404
    – s_ha_dum
    Jul 31, 2013 at 20:41
  • 4
    The whole point of making a post private is to prevent not logged in users (including robots) from having access to it (preventing indexing, actually). If you want to give full access to those posts just don't make them private. If you need to group them just add a private tag or put them in a category called private.
    – tao
    Apr 7, 2015 at 10:37

3 Answers 3

1

As already mentioned in the comments, private posts are private for a good reason.

If you want to change this behaviour, you could probably alter the get_posts() which is used to retrieve your posts.

I did not try it, but this could work:

$args = array(
    'post_status' => array(
                         'publish',
                         'private'
                     )
);
$myposts = get_posts($args);
0
0

You can add capability of reading private post to any user role like this.

Add these code below to functions.php in wordpress theme folder:

$subRole = get_role( 'author' );
$subRole->add_cap( 'read_private_pages' );

Here you'll see a details tutorial http://www.shartd.com/let-subscriber-see-private-post-wordpress/

-1

I'm confused by the answers.

When I have "private" posts/pages, I cannot see them when I am logged in. I can only see them when I am the Admin.

About the OP's question--

I use the WPDB class methods to extract post_content from the database selectively to bypass permissions:

global $wpdb; //global wpdb class may not work everywhere...
$post_id = (int) $post_id; // you supply $post_id && make sure int...
$result = $wpdb->get_var("SELECT post_content FROM wp_posts WHERE ID = $post_id");
if(!empty($result)) $result = apply_filters('the_content',$result); //will also execute shortcodes in the content
//do stuff like echo $result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.