WordPress.org

Forums

[resolved] Password Protect Pages With Custom Fields (8 posts)

  1. FelixDaHousecat
    Member
    Posted 2 years ago #

    Can anyone tell what code and exactly where I should place it on a page with a custom field so that everything is hidden?

  2. graphical_force
    Member
    Posted 2 years ago #

    We need much more information in order to help you. Can you please describe exactly what you are trying to do or how might you see the code working?

  3. FelixDaHousecat
    Member
    Posted 2 years ago #

    Hi, thank you for your reply. I have made a page for my template that inserts an Adobe Lightroom gallery. It works perfectly. However, I want that gallery/page to be password protected. When I publish the page as password protected the gallery still shows. I believe that I need to add some extra code to make the custom field protected too. This is the part that I can't seem to do. Here is what I have done so far:

    get_header(); ?>
    
    <?php $gallery_link = get_post_meta( get_the_ID(), 'gallery_link', true ); ?>
    
    		<div id="primary" class="content-area span12">
    			<div id="content" class="site-content" role="main">
    
    				<?php while ( have_posts() ) : the_post(); ?>
    
    				<h1><?php the_title(); ?></h1>	
    
    				<?php the_content(); ?>
    
                    <iframe src="<?php echo $gallery_link; ?>" width="100%" height="1100"></iframe>	
    
    				<?php endwhile; // end of the loop. ?>
    
    			</div><!-- #content .site-content -->
    		</div><!-- #primary .content-area -->
    
    <?php get_footer(); ?>
  4. keesiemeijer
    moderator
    Posted 2 years ago #

  5. FelixDaHousecat
    Member
    Posted 2 years ago #

    Hi, thanks, I have tried this but I don't understand where to insert the code and if I use the example in its exact form. Can you tell where I insert the code shown?

  6. keesiemeijer
    moderator
    Posted 2 years ago #

    Try this:

    <?php get_header(); ?>
    
    <?php $gallery_link = get_post_meta( get_the_ID(), 'gallery_link', true ); ?>
    
    		<div id="primary" class="content-area span12">
    			<div id="content" class="site-content" role="main">
    
    				<?php while ( have_posts() ) : the_post(); ?>
    
    				<h1><?php the_title(); ?></h1>
    
    				<?php the_content(); ?>
    				<?php if ( ! post_password_required() && !empty( $gallery_link ) ) : ?>
    				<iframe src="<?php echo $gallery_link; ?>" width="100%" height="1100"></iframe>
    				<?php endif; ?>
    
    				<?php endwhile; // end of the loop. ?>
    
    			</div><!-- #content .site-content -->
    		</div><!-- #primary .content-area -->
    
    <?php get_footer(); ?>
  7. FelixDaHousecat
    Member
    Posted 2 years ago #

    Oh my god! Thank you so much - It works! I spent hours yesterday trying to fix this. Thank you so much for your help :o)

  8. keesiemeijer
    moderator
    Posted 2 years ago #

    You're welcome :)

Topic Closed

This topic has been closed to new replies.

About this Topic