Search code examples
wordpresspassword-protectioncustom-post-type

Wordpress Password Protect Archive and Single Posts for Custom Post Type


Is there an easy way to password protect an archive and single posts of a custom post type?

I found this article on password protecting single posts, but am still lost on the archive loop. I would want it only display the password box until the user has logged in.

https://wordpress.stackexchange.com/questions/4952/forcing-all-posts-associated-with-a-custom-post-type-to-be-private

Thanks,


Solution

  • For single pages you could just edit single.php and add something along the lines of:

    <?php
    
    if ( is_user_logged_in() ) {
      // Show Post to Logged in User
    } 
    else {
      //Show password field
    }
    
    ?>
    

    If like you mentioned you are using a custom post type or an archive template you could apply the same method as above to single-[custom-post-type-name].php or archive.php