SOLVED: Condition using "contains" on ACF options field (checkbox) not working - VIDEO inside

Hi everyone. I had a wonderful idea but I can’t get it to work.
I want to use different “contact links” at different places and set up an ACF repeater on an options page to add all the options. For every item there’s an icon, a text and a link, as well as a checkbox that asks WHERE this item should be displayed. (footer contact links, social media links, floating menu…)
My idea was to be able to loop these items and at different locations show only the items that match the criteria. For example in the footer I would have a social menu showing only the social icons.
I am looping through the items repeater and that works fine. But as soon as I add my desired condition:
fieldname contains socialmedia


it displays nothing! So either it’s not possible to add a condition like that to a repeater field or I am doing something wrong.

I also made a video showing the whole thing for anyone interested in the full story: Bug or Stupidity with loop ...

Thanks for anyone who can shed some light on this!
Anja

Hi @netzmaedchen

As per my email reply:

The reason you get nothing is because of the condition placed on the loop.

In Bricks, the condition is always executed before the loop.
If you place the condition to check if the ACF checkbox contains “social”, that means Bricks is trying to retrieve this field BEFORE the repeater loop.

Obviously, it’s empty before the loop so the condition is evaluated as “False” and the query loop will not run.

You can only place the condition inside the loop (A dummy div/block wrapper)

But this will cause some empty divs generated. So you have to use CSS to hide those empty divs.

Alternatively, the only possible way to achieve what you want is to use this PHP Filter to amend the Repeater result (Remove any repeater loop if the checkbox contains something) Filter: bricks/query/result – Bricks Academy

Regards,
Jenn

1 Like

Thank you so much! I feel stupid now. Totally makes sense.
I will find another way, no problem!
Regards
Anja