Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want private posts (for those not logged in) to use the single.php template just as public posts do, at the moment they get thrown over to the 404.php template.

I've had a good look through the core files but I cannot find where the template change (note: this is not a redirect) happens.

Can anyone help?

Edit

To explain why I want this, I want all visitors to see a preview of the content, but logged in "members" to see the entire post content.

share|improve this question
    
Have you done the usual rigamarole (disable plugins, switch to default theme) to see if the 404 theme load is coming from somewhere other than WP core? –  Pat J Jun 5 '13 at 14:33
    
I don't have any plugins installed, this is default functionality. I just want to disable this default functionality so private posts (for those who aren't logged in) shows the single.php template. –  Ben Everard Jun 5 '13 at 14:37

2 Answers 2

According to the Content Visibility page, Private posts are visible only to those with sufficient permission levels. WordPress doesn't expose them to non-logged-in users at all, hence (presumably) the 404.

If you want to display a limited preview to non-members, instead of setting the post to Private, you could try something like this:

add_filter( 'the_content', 'wpse101968_preview' );
function wpse101968_preview( $content ) {
    if( is_single() ) {
        if( ! is_user_logged_in() ) {
            $content = get_the_excerpt();
        }
    }
    return $content;
}

And then your non-logged-in visitors will see the post's excerpt instead of the entire post. You can customize the excerpts, too, so that they see only what you want them to see.

References

Codex:

share|improve this answer
    
+1 modifying public content to fit requirements would be more robust than hacking up private content to be non-private –  Rarst Jun 5 '13 at 16:32

You are not seeing a redirect, to confirm your own observation, so much as you are seeing just what it looks like-- a "File Not Found". Take a look at the query in the source around line 2438 (among others). The status of the post is part of the query itself, so if the status doesn't match then no posts are found and that means 404. As you can see from the code, status is pretty rigidly protected. That is proving difficult to override.

I'd recommend using a custom post type for you "logged in only" posts. That is going to be much easier to control both on the front end and the back end.

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.