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 :| )
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 :| )
I solve in this way. In the custom template page, that contain the loop of custom post type I add this code:
<?php
/** Template Name: Restrict Area */
get_header();
?>
<?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(); ?>
<?php
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.