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.

Read More

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

Thanks,

Related posts

Leave a Reply

2 comments

  1. The only way I’ve found to quickly password-protect the archive is by creating a template that retrieves the custom post type data and associating it with a page that can be password protected.
    http://codex.wordpress.org/Page_Templates

    Once that page is password protected, you find the post ID to apply it to the single-{your_custom_post_type}.php like so:

    <?php
    if ( !post_password_required('{protected_post_id}') ) : ?>
    
    //protected content here
    
    <?php else:
        //show the password form of the protected page
        echo get_the_password_form('{protected_post_id}');                 
    
    endif; ?>
    

    This saves you from having to password-protect every post under your custom post type.

  2. 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