Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Advanced Custom Fields - Check if multiple get_fields exist? WordPress

  • SOLVED

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 );

?>


<br />

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

<strong><?php if ($promotions) { ?></strong>

<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>

Answers (1)

2012-12-05

Dbranes answers:

Hi, you could try this:

$promotions = (isset( $rider_plan_code) && isset($low_rate_finance_code) && isset($custom_promo_code ))?true:false;



Josh Cranwell comments:

Hi Dbranes,

It still seems to echo everything?

Even when none of the variable have a value?

Weird right?


Dbranes comments:

here is another possibility if you want to use strlen() instead of isset()

$promotions = (strlen($rider_plan_code) * strlen($low_rate_finance_code) * strlen($custom_promo_code ) >0)?true:false;


Dbranes comments:

ps:

If you need all the three variables to be set (you can use the above code)

$promotions = (strlen($rider_plan_code) * strlen($low_rate_finance_code) * strlen($custom_promo_code ) >0)?true:false;


or if you need at least one of the variables to be set:

$promotions = (strlen($rider_plan_code) + strlen($low_rate_finance_code) + strlen($custom_promo_code ) >0)?true:false;


i.e. where I just replaced the multiplication with addition.


Josh Cranwell comments:

Awesome the second version with the addition worked great.

Many thanks for your help Dbranes