I have an ACF checkbox sub field in a group field on an options page. It has 4 options, and is set to return “Value”.

I am trying to make a series of radio buttons that correspond to these options in various places around a site. These should display content only for the choices that have been checked.

Using the method given under “Conditional logic” at https://www.advancedcustomfields.com/resources/checkbox/ I cannot get the unchecked options not to show. No matter the selection all 4 options are always visible.

Here’s the code I’m using (checkbox field must be stored as a variable since it is in an options page):

    if(have_rows('currencies', 'option')): while(have_rows('currencies', 'option')): the_row();
        $currency = get_sub_field('currency');
    endwhile; else : endif;

<form class="currencies" name="currForm">
    <?php if($currency && in_array('GBP', $currency)): ?>
        <input type="radio" id="gbp" name="curr" value="gbp" checked>
        <label for="gbp">GBP<div class="highlight"></div></label>
    <?php endif; ?>
    <?php if($currency && in_array('ZAR', $currency)): ?>
        <input type="radio" id="zar" name="curr" value="zar" >
        <label for="zar">ZAR<div class="highlight"></div></label>
    <?php endif; ?>
    <?php if($currency && in_array('USD', $currency)): ?>
        <input type="radio" id="usd" name="curr" value="usd">
        <label for="usd">USD<div class="highlight"></div></label>
    <?php endif; ?>
    <?php if($currency && in_array('EUR', $currency)): ?>
        <input type="radio" id="eur" name="curr" value="eur" >
        <label for="eur">EUR<div class="highlight"></div></label>
    <?php endif; ?>

If I perform a var_dump on $currency I get:

array (size=4)
  0 => string 'GBP' (length=3)
  1 => string 'ZAR' (length=3)
  2 => string 'USD' (length=3)
  3 => string 'EUR' (length=3)

My ACF settings are here:

enter image description here

Here is a page where this is happening: https://bxd.dev.matmartin.studio/membership — The buttons marked GBP, ZAR, USD and EUR are generated by the code above. Currently the GBP, ZAR and EUR boxes are checked, so the USD button should not be visible.

enter image description here

I think I have used this approach before successfully – I may have overlooked something very obvious in this case but I'm not seeing it.

Many thanks for any help.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy