Support

Account

Home Forums Front-end Issues Empty group always returns true Reply To: Empty group always returns true

  • Thanks for the reply. I did end up figuring that out. The documentation is confusing to me on this since in the basic example it does an if get_field() check which can only return true making it seemingly useless to check. I guess there are still cases when the template might not have that field so you would want to check if the group exists but that’s not immediately clear to me from the documentation. My incorrect assumption was that the if statement in the documentation was checking if the group had any values inside of it’s fields. It seems in most cases with ACF “if get_field()” usually returns true after the admin has entered some data, not after the field is created in the ACF ui. Anyway, thanks for the reply!

    <?php
    		
    // vars
    $hero = get_field('hero');	
    
    if( $hero ): ?>
    	<div id="hero">
    		<img src="<?php echo $hero['image']['url']; ?>" alt="<?php echo $hero['image']['alt']; ?>" />
    		<div class="content">
    			<?php echo $hero['caption']; ?>
    			<a href="<?php echo $hero['link']['url']; ?>"><?php echo $hero['link']['title']; ?></a>
    		</div>
    	</div>
    	<style type="text/css">
    		#hero {
    			background: <?php echo $hero['color']; ?>;
    		}
    	</style>
    <?php endif; ?>