$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Password protection template and automatic fall in post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Password protection template and automatic fall in post type

matteradmin9PV0评论

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 :| )

Share Improve this question edited Mar 8, 2019 at 16:47 MikeNGarrett 2,6811 gold badge20 silver badges29 bronze badges asked Mar 8, 2019 at 16:36 Antonio CarboneAntonio Carbone 216 bronze badges 1
  • Show us your code, please. It's a little bit hard to guess what solutions you're using currently. – Krzysiek Dróżdż Commented Mar 8, 2019 at 17:30
Add a comment  | 

1 Answer 1

Reset to default 0

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.

Post a comment

comment list (0)

  1. No comments so far