Problem with conditions

Hello everybody,

I know this came up already (and I also posted this question in the facebook group) but I really, really want this to work. Maybe someone here knows what’s going on.

I’m trying to use conditions to hide/unhide a container: it should hide when a certain ACF-field (text) (acf_dinsdag_tijd) is empty.
The container (the one I’m trying to apply the condition to) consists of two blocks: block #1 has a heading, block #2 has a query loop with dynamic heading and text elements (the ACF field act_dinsdag_tijd is linked to the custom post type where this query loop is based on, maybe that is important)

No matter what I do or select in the conditions, (see the image) the container just isn’t shown. It somehow always sees the ACF field as empty and therefore it never loads the container.

My question is: am I just doing it wrong? (maybe it is not possible to do it the way I’m trying to do it?) or should this be working and is it a bug? If so, is there a workaround?


Schermafbeelding 2023-01-10 om 16.52.08

I use the condition exactly the same as you do. It works for me.

Can you remove the condition and see if the loop query outputs the acf field content? That would mean that the condition is not working.

But I could imagine that your query loop is not correct because as I wrote, the condition works for me perfectly with != and an empty value field.



On a second thought…

Did you define the condition on the block that contains the query loop?

I think you have to define the condition under the query loop.

I mean like this:

Block with query loop (no condition)

  • Block (with condition)
    — Item1 to show if condition above is true
    — Item 2 to show if condition above is true
    — etc.

Try that.



Ok, I quickly made a test for you.

See my screen shot below.

Accordingly to what I wrote above, I made a block without a condition that contains the query loop. Below that I added two blocks. The second block has a condition that checks if ACF field {post_terms_post_tag} is not empty.

You see from the results that only posts that have something in that field are shown.

So I can confirm what I wrote above. You have to put the condition under the query loop and then it will show or hide the block depending on the condition.



Hey Patric,

It works when I add the condition inside the block with the query loop (the way you do it in your test) but I want the condition to apply to the whole container, not only to elements that are inside the block with the query loop. (see the screenshot I made) Apparently this just isn’t possible, which is a pity.

Thanks for your input!

Schermafbeelding 2023-01-12 om 16.40.00

I think the condition cannot work on the query loop itself, but only on the items the query finds because they contain the field and not the query.

Alk, why don’t you just add one additional container under your query container and then use the condition on that container, with everything below that container?

So the second container with everything below in it will be shown or hidden depending on the condition.

In my example I also show / hide the whole block that has the condition.



Yes that would be a solution, but the heading in block #1 should not be repeated. (It ‘introduces’ the information that is query looped) That’s why I want the query loop to be only active on block #2. But it indeed seems that because the query loop isn’t defined in the wrapping container (but instead in one of the blocks it contains) it cannot ‘find’ the fields in the condition.

Thanks again for your insights.

OK, last try… :wink:

Do you know if the first item found in the loop is always the same? If yes, you can use this trick to only show the text in block 1 once.

Do the following:

  1. Add a new block directly under the loop and put everything directly below it (screen shot 1).


  1. Add a condition to this new block that checks if your acf field is empty (screen shot 2). In my example, I check if the acf field “name_autor” is not empty. So if the acf field is empty, nothing at all will be shown.


  1. Add a condition to the block with the text that you only want to show once and make the condition that it only shows if the condition is true (screen shot 3). Now here comes the trick: I know what the value in the acf field “name_autor” will be in the first post. So I made the condition that it only shows if the value of the acf_field is "Reini im August 2022. From the second post onwards it will not show anymore.


The result:

Remark: If you don’t know which item will always be found in the loop first, you can also make a dummy post that will be always the first post in the loop and you can use that to print the text in block 1 once. In the condition of block 1 you can then even use a dedicated acf field that is only filled in this dummy post to show the content of block 1 once.

Maybe you can do it with the PHP function placed before the container. Check if {post_terms_post_tag} is empty, return “yes” if not, echo function in condition and show container if the value is “yes”. Hope that makes some sense.

Hey Patric,

I gave it a try and it is the best solution I think. But because the fields differ every time, I have to create a dummy field and I have to tell the client to only in the first post, type in an exact string of words. It would be nice if it was a bit more fool proof and more simple: field empty —> no container.

Thanks very much for your effort and time!

Hello Goran,

Thanks. Yes this makes sense. But I have no idea how to implement this function. Do I do this in Bricks or via a code snippet? I’m a bit of noob when it comes to PHP (or any programming language :grinning: )

Hello Alk,

I’m also a noob when comes to PHP (was very good with COBOL some decades ago :slight_smile: ). I have done it with the Code element in the Bricks but lost the code :frowning: . It was on the test site. If I remember correctly I found it on the Bricks FB group.


That’s a pity… Thanks anyway!

Hi there

I quickly wrote a function for you:

function check_acf_field_if_empty() {
$value = get_field( “name_autor” );
if (empty($value )) {
return “empty”;
} else {
return “filled”;

change “name_autor” to the acf field you want to check. This function will return “empty” as a text if the field is empty or “filled” if the field has content.

You can put his function either into the functions.php (of the bricks child theme) or you can use WPCodeBox.

You can then use {echo:check_acf_field_if_empty()} in the condition.

But I doubt that this solves your problem, because you still have to run this function inside a loop, otherwise it will also return empty all the time because it does not know which post to check.



Thanks I will give that a try!

Hi Alk, it’s me again.

I have one more solution. This one does not need any fiddling with post items.

I got the idea to use css classes.

You can use the css pseudo class nth-child to select the first item of the loop. Here is the output of my test loop with the css pseudo class:

This is how I did it:

I make two identical query loops. In the first loop, I add the two pseudo classes :nth-child(1) (this targets the first loop item) and :not(:nth-child(1)) (this targets all other loop items) to the loop block.


When selected pseudo class :nth-child (1), in my test I chose font color red in the typography to show that the pseudo class is working. Anyway, this pseudo class is only valid for the first item in the loop.

When selected pseudo class :not(:nth-child(1)), I enter font size as 0 in Typography. This makes all items except the first one disappear.


In the second loop, that has no pseudo classes, you can then define your loop items as you want.

You can add your conditions to all the items in both loops as you need as the conditions are now in the loop and bricks will find the field values in the posts.



Hey Patric

This could work! Once again thanks very much for your effort and time!

I’ll let you know if it works!

Hey Patric,

Perfect solution! This way it works without needing the conditions.

Only thing is that setting the font size to 0 didn’t work. So instead I used display: none. Does this make a difference?

Hi Alk

Display: none is even better.

But interestingly, that didn’t work for me, but font size 0 did.

I think if you have a font size defined in the typography of the element under the block element (child), that css setting „overrules“ the css setting coming from the block (parent of the element).

Good to hear that it works.