Support » Fixing WordPress » Password protected posts showing for twice

  • Resolved David Gard


    Hey all,

    I’m using Password Protected Posts for the first time and have hit a couple of snags –

    1. The password from seems to be called on both ‘the_content();andget_the_content()`, so if I run a check to see if there is content (as other output is needed if there is), the password form is displayed twice.
    2. I need to display a list of media attached to the Post, but this is being shown regardless of the Password being entered (which I assume is only tied to the content of the Post, judging from the above, as opposed to the display of the Post itself

    Are these problems that others have come across before? If so, is there a proper solution?


Viewing 1 replies (of 1 total)
  • David Gard


    Ok, so for this you should check if a Password is required before showing any of the post content, that way when the_content() or get_the_content() are called, the password has already been entered, so the form will not show up again.

    This also prevents other content that is not called via those functions (like my list of attachments) from being displayed before the password has been entered.

    Note that this code is for use in The Loop.

    <?php /** Check to see if a password is required */ ?>
    <?php if(post_password_required($post)) : ?>
    	<?php echo get_the_password_form(); ?>
    <?php else : ?>
    	<?php if(get_the_content() !== '') : ?>
    		<div id="post-content">
    			<?php the_content('<p class="serif">Read the rest of this entry »</p>'); ?>
    		<div class="line-seperator-dotted"> </div>
    	<?php endif; ?>
    	<?php $children = get_children(array('post_parent' => $post->ID)); ?>
    	<?php display_attachments($children); ?>
    <?php endif; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Password protected posts showing for twice’ is closed to new replies.