Support

Account

Home Forums Add-ons Options Page Using || Or with get_fields

Helping

Using || Or with get_fields

  • I am trying to get a FontAwesome icon to display if any one of the ACF fields in an ACF Options Page has a value. I just can’t seem to get the ‘or’ working correctly and wonder if there is a problem in the code. Any help appreciated.

    add_shortcode( 'business_address', function () {
    	$option_fields = get_fields( 'options' ); ?>
    	<div class="acf_address_block">
    		
    	<?php if( get_field('acf_address') ||
    	 		get_field('acf_address_2') ||
    	 		get_field('acf_address_city') ||
    	 		get_field('acf_address_state') ||
    	 		get_field('acf_address_postcode') ||
    	 		get_field('acf_address_country')
    	 ): 
    	
    	echo '<div class="acf_address_icon"><i class="fas fa-map-marker-alt"></i></div>';	
    	else:
    	endif;
    	?>
    	<div class="acf_address_content">
    	<?php
    	if( get_field('acf_address') ); ?><span class="acf_address"><?php the_field( 'address', 'option' ); ?></span><?php
    	if( get_field('acf_address_2') ); ?><span class="acf_address_2"><?php the_field( 'address_2', 'option' ); ?></span><?php
    	if( get_field('acf_address_city') ); ?><span class="acf_address_city"><?php the_field( 'city', 'option' ); ?></span><?php
    	if( get_field('acf_address_state') ); ?><span class="acf_address_state"><?php the_field( 'state', 'option' ); ?></span><?php
    	if( get_field('acf_address_postcode') ); ?><span class="acf_address_postcode"><?php the_field( 'postcode', 'option' ); ?></span><?php
    	if( get_field('acf_address_country') ); ?><span class="acf_address_country"><?php the_field( 'country', 'option' ); ?></span>
    		</div>
    	</div>
    <?php
    } );
  • Hi @nikcree

    If the fields are all from an options page, should they not be more like:

    
    if( get_field('acf_address','option') ||
    	 		get_field('acf_address_2','option') ||
    	 		get_field('acf_address_city','option') ||
    	 		get_field('acf_address_state','option') ||
    	 		get_field('acf_address_postcode','option') ||
    	 		get_field('acf_address_country','option')
    	 ): 
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.