Display Private Posts to Log in Users

 In All, Posts, Users

How display private posts to logged-in users

To display private posts to your logged-in users, you will need to add a custom field called “private” for each private post and give it a value of “true”. Then, replace your default WordPress loop with the following:

This custom loop will check each post for the presence of a custom-field value of true. For each post that has this value, the loop will then check to see if the user is logged into your site. If the user is in fact logged in, the loop will display the private posts to logged-in users

. Public posts will be displayed as usual and regardless of whether the user is logged in or not.

Learn how to email post contributors when their posts are published @ https://www.nuno-sarmento.com – Nuno Sarmento

Recommended Posts
Showing 8 comments
  • Nuno Sarmento

    Thank you for comment Kristen

  • MoreVisas

    Thanks for finally writing about >Display Private Posts to Logged-in Users – WordPress Code Snippets <Liked it!

  • Reply

    Hey there! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve worked
    hard on. Any tips?

    • Nuno Sarmento


      You can take some good measures in order to prevent most of the attacks.
      Keep plugins and themes updated

      Those are simple things that yo can do to prevent attacks.

  • rene jimene facebook

    Hey would you mind letting me know which web host you’re using?
    I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a
    lot quicker then most. Can you suggest a good hosting provider at a
    honest price? Thank you, I appreciate it!

    • Nuno Sarmento

      Hi Rene,

      Thank you for visiting my website. My website is running on my private server ( AWS Amazon ) which is free in first year 🙂 you just need to setup the server by yourself. If you need help please let me know

  • Aaron Quest

    Hi there. Please tell me how can i add a custom field called “private” for each private post and give it a value of “true”. ? And i should put the code to functions.php of my themes ??

    • Nuno Sarmento

      Hi Aaron you should use this code snippet on you page-template.

Leave a Comment

Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Start typing and press Enter to search

Display Last Modified Time and Date for Postswordpress new posts