I have a custom template that I protect with a password. This template shows a listing of posts from a custom post type.

The password on this custom template works, but the single posts are not protected with the same password. If I have the url of single post from my custom post type, I see the content of that post.

I would like the password for the custom template to also protect these posts.

Is this possible? If not, what other way can I use?

Thanks (and sorry for my English :| )

  • Show us your code, please. It's a little bit hard to guess what solutions you're using currently. – Krzysiek Dróżdż Mar 8 '19 at 17:30

I solve in this way. In the custom template page, that contain the loop of custom post type I add this code:

/** Template Name: Restrict Area */

<?php if ( ! post_password_required() ) { ?>

//content of the page with loop of custom post type 

<?php } else{ 

    echo get_the_password_form($post->ID); 

} ?>

<?php get_footer(); ?>

In single-custom-post-type.php this code:

 <?php get_header(); ?>

 if ( !post_password_required(id_page_custom_template) ) : ?>

 //content single

<?php else: ?>

    <?php echo get_the_password_form(id_page_custom_template); ?>    

<?php endif; ?>

<?php get_footer(); ?>

Where id_page_custom_template must be replaced with the id of the page with custom template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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