Support

Account

Home Forums General Issues Hide section if fields are empty

Solved

Hide section if fields are empty

  • Hi everyone,
    I have a section I want to hide if the fields are empty. I already read the existing threads to similar problems but couldn’t adapt it to mine. Hope someone could point me in the right direction.

    <?php $feature = get_field('section_feature'); if($feature) : ?>
    		<section class="bg-blue text-white">
    			<div class="container">
    				<div class="arrow-down pb-5"></div>
    			</div>
    			<div class="container pb-5">
    				<h3 class="text-green"><?php echo $feature['headline']; ?></h3>
    				<div class="row">
    					<div class="col-md-6"><?php echo $feature['text_left']; ?></div>
    					<div class="col-md-6"><?php echo $feature['text_right']; ?></div>
    				</div>
    			</div>
    		</section>
    		<?php endif; ?>

    Thanks in advance.

  • I am assuming by looking at your code that your using a group field. In this case you need to check the sub field values because the field will always be an array that is not empty.

    
    $feature = get_field('section_feature');
    if ($feature['headline']) {
      ...
    }
    
  • Absolutely. That did the trick of course.
    Thank you, John. Great support as always.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.