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?


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.

  • 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, 2013 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. Jun 5, 2013 at 14:37

3 Answers 3


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.



  • +1 modifying public content to fit requirements would be more robust than hacking up private content to be non-private
    – Rarst
    Jun 5, 2013 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.


How do you set password protected posts to be viewed by logged-out users? We created the functionality and all logged-out users are getting a 404 after inserting the password.

  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 6 at 15:54
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review Mar 7 at 14:47

Your Answer

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

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