WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
possible duplicate of Prevent private post 404 – s_ha_dum Jul 31 '13 at 20:41
3  
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. – Andrei Gheorghiu Apr 7 '15 at 10:37

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);
share|improve this answer

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/

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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