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?
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.
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.
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.
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:
Add a new block directly under the loop and put everything directly below it (screen shot 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.
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.
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.
Regards,
Goran
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. 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 )
I’m also a noob when comes to PHP (was very good with COBOL some decades ago ). I have done it with the Code element in the Bricks but lost the code . It was on the test site. If I remember correctly I found it on the Bricks FB group.
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.
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.
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).