I can only really seem to find documentation on wether one get_field exists or not.

Is it possible to put multiple get_field’s into one variable and use that variable to check if any of the singular get_field variables exist?

So for example I have these variables below, and then put them all into one: $promotions

<?php 

    $rider_plan_code        = get_field('rider_plan_code');
    $low_rate_finance_code  = get_field('low_rate_finance_code');
    $custom_promo_code      = get_field('custom_promo_code');

    $promotions = isset( $rider_plan_code, $low_rate_finance_code, $custom_promo_code );

?>

Then I am using this… <?php if ($promotions) { ?> to check if any of those variables exist, but its not working.

Can anyone point out what I’m doing wrong?

Many Thanks


See below how I am using this…

<div class="btn-group">

    <a class="btn " href="#"><i class="icon-share"></i> Post to wall</a>

    <a class="btn <?php if ($promotions) { echo 'dropdown-toggle'; } ?> pricing-btn" href="#" title="Pricing" <?php if ($promotions) { echo 'data-toggle="dropdown"'; } ?>>
        <strong>&#163;<?php the_field('rrp-pound-sterling'); ?></strong><?php if ($promotions) { echo ' <span class="caret"></span>'; } ?>
    </a>

    <?php if ($promotions) { ?>

        <ul class="dropdown-menu">
            <?php if ($rider_plan_code) { ?><li><a href="#">Rider Plan</a></li><?php } ?>
            <?php if ($low_rate_finance_code) { ?><li><a href="#">Low Rate Finance</a></li><?php } ?>
            <?php if ($custom_promo_code) { ?><li><a href="#"><?php echo $custom_promo_name; ?></a></li><?php } ?>
        </ul>

    <?php } ?>

</div>

3 Answers
3

ACF does not return NULL variables, it will return an empty. Try checking with !empty instead of isset.

Leave a Reply

Your email address will not be published. Required fields are marked *