2

Here is mine below code. Now thing is that It perfectly asks the password for secured page.

But if even I add correct password. I still page asking for password.

Below is mine code.

<?php
/**
 * Template Name: Page
 *
 */
global $post; 
if ( ! post_password_required( $post ) ) {
get_header();

?>
<div id="Content">
    <div class="content_wrapper clearfix">
secured content here

</div>
</div>
<?php 

get_footer(); 
}else{
    // we will show password form here
    echo get_the_password_form();
}
  • Your current code looks strange, e.g. ?php and /div>, please add your indented working code. Can you password protect normal pages, without this template? – birgire Sep 1 '15 at 10:29
  • 1
    updated,sorry I written here that section manually. – nirmal Sep 1 '15 at 10:30
  • 1
    Try adding while ( have_posts() ) { the_post(); } at the top of the file - this will correctly set up the loop (even though it's just one post/page) and make sure all the code that follows functions correctly. – TheDeadMedic Sep 1 '15 at 13:30
  • just adding it will work ? thing is that there is nothing going to come from the post. Still I should Add it ? – nirmal Sep 2 '15 at 9:44
  • yup @TheDeadMedic it worked like charm. As I added that code after get_header(). But still it worked like charm. thanks. – nirmal Sep 2 '15 at 9:50
2

I solved issue with suggestion of @TheDeadMedic.

Below is the code. As he told added while have post. I added it after header.

<?php
/**
 * Template Name: Page
 *
 */
global $post; 
if ( ! post_password_required( $post ) ) {
get_header();
while ( have_posts() ) { the_post(); }
?>
<div id="Content">
    <div class="content_wrapper clearfix">
secured content here

</div>
</div>
<?php 

get_footer(); 
}else{
    // we will show password form here
    echo get_the_password_form();
}
|improve this answer|||||

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.