Display terms only if ACF checkbox is checked (also: multiple conditions)

I have the following code.

<Loop type=taxonomy_term taxonomy=topic>
  <If loop type=podcast taxonomy=topic terms="{Field id}" >
    <If loop acf_checkbox=featured_topic>
      <a href="{Field url}">
        <Field title />
      </a>
    </If>
  </If>
</Loop>

I’m trying to check whether the featured_topic field is checked and only show those terms. This seems to work, but I’m wondering if this is the right approach for multiple conditions or if there is a way to combine the if statements.

I see, I thought the second condition should be:

<If acf_checkbox=featured_topic>

…without “loop”, which tells the If tag to check if a loop can be created (and is not empty). But from the documentation, it looks like the checkbox field must be a loop. So the way you wrote it is correct, and should work.


For combining multiple conditions - the simplest way is to nest them like you did.

Unfortunately there’s no convenient method like AND, because of how HTML attributes work (there cannot be multiple attributes of the same name).

There is a feature called Logic variables, which is meant for building complex conditions. It’s documented here: https://loop.tangible.one/tags/if#logic-variable-type

To be honest, I think no one has really used the feature yet, so I’m not sure if it’s actually practical.

1 Like

In the newest plugin version, the If tag has been integrated deeper with ACF field types, including those that are loops, such as acf_checkbox, acf_relationship, etc.

So the following should work as expected now, without having to use “If loop”.

<If acf_checkbox=featured_topic>
2 Likes

I’ve used it a handful of times! It’s rarely necessary, but when it is it’s immensely practical.

1 Like