WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Password protected posts showing for twice (2 posts)

  1. David Gard
    Member
    Posted 1 year ago #

    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?

    Thanks.

  2. David Gard
    Member
    Posted 1 year ago #

    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>
    
    		<div class="line-seperator-dotted"> </div>
    
    	<?php endif; ?>
    
    	<?php $children = get_children(array('post_parent' => $post->ID)); ?>
    	<?php display_attachments($children); ?>
    
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.