# Loop and condition

**URL:** <https://forum.bricksbuilder.io/t/loop-and-condition/8102>\
**Category:** How To\
**Created:** [November 22, 2022, 11:45pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102 "2022-11-22T23:45:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrespereirabr](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/andrespereirabr/32/2556_2.png) [@andrespereirabr](https://forum.bricksbuilder.io/u/andrespereirabr)\
**Post date:** [November 22, 2022, 11:45pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/1 "2022-11-22T23:45:54Z")

</div>

If I put the condition on the same element with loop, it doesn’t work. If I put the condition on the card, and the loop on the parent div, it also doesn’t work as I would like.

The condition should hide the card if a text field is empty.

What am I doing wrong? 🤔

 ![image](https://forum.bricksbuilder.io/uploads/default/original/2X/c/caba91ec96ad682cac95ae1cc41aff8b5a579b2d.jpeg)

 ![image](https://forum.bricksbuilder.io/uploads/default/original/2X/7/7ec0c89f13b05791b85930779cf5537920bdd232.jpeg)

---

<div class="post-metadata">

**Author:** ![stabilo](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@stabilo](https://forum.bricksbuilder.io/u/stabilo)\
**Post date:** [November 24, 2022, 7:47am UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/2 "2022-11-24T07:47:05Z")

</div>

Thank you for this question. Looki also for a solution for a while \>\> [ACF True/False = Show/Hide Custom Post Type Condition](https://forum.bricksbuilder.io/t/acf-true-false-show-hide-custom-post-type-condition/7947)

---

<div class="post-metadata">

**Author:** ![andrespereirabr](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/andrespereirabr/32/2556_2.png) [@andrespereirabr](https://forum.bricksbuilder.io/u/andrespereirabr)\
**Post date:** [November 24, 2022, 11:07am UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/3 "2022-11-24T11:07:47Z")

</div>

@timmse please see this.

Working with Metabox.

---

<div class="post-metadata">

**Author:** ![stabilo](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@stabilo](https://forum.bricksbuilder.io/u/stabilo)\
**Post date:** [November 24, 2022, 5:32pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/4 "2022-11-24T17:32:16Z")

</div>

Another example where it doesn’t work. \>\> [https://drive.google.com/file/d/1j-FsqbZaMj8uuUMApyKpS-3FFAuwRqPA/view?usp=share\_link](https://drive.google.com/file/d/1j-FsqbZaMj8uuUMApyKpS-3FFAuwRqPA/view?usp=share_link)

---

<div class="post-metadata">

**Author:** ![andrespereirabr](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/andrespereirabr/32/2556_2.png) [@andrespereirabr](https://forum.bricksbuilder.io/u/andrespereirabr)\
**Post date:** [November 29, 2022, 4:40pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/5 "2022-11-29T16:40:19Z")

</div>

1.6 Beta 2 is live!  
Very happy with the frequent updates! I hope they manage to fix the integration problem between Metabox, Loop and Conditions.

Not yet this time.

---

<div class="post-metadata">

**Author:** ![Tobias](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tobias](https://forum.bricksbuilder.io/u/Tobias)\
**Post date:** [November 29, 2022, 5:06pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/6 "2022-11-29T17:06:53Z")

</div>

What Problem? I don’t get it.

If you want to hide a card when a dynamic text field is empty you need  
to set the condition to your card. Not to your loop like you did in the video.

![Shared with CloudApp](https://forum.bricksbuilder.io/uploads/default/original/2X/f/ff30cb64caba478126d4615c0e198317987527cd.jpeg)

And the condition on the card would be like this:  
 ![Shared with CloudApp](https://forum.bricksbuilder.io/uploads/default/original/2X/d/d28b8b97278adde004ac068f72af8e90b66b7c0d.jpeg)

So the card only shows if there is any content in the text field.

---

<div class="post-metadata">

**Author:** ![andrespereirabr](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/andrespereirabr/32/2556_2.png) [@andrespereirabr](https://forum.bricksbuilder.io/u/andrespereirabr)\
**Post date:** [November 29, 2022, 5:18pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/7 "2022-11-29T17:18:08Z")

</div>

Yeah… I already tried to do exactly as you show, but for some reason it doesn’t work as it should.

![image](https://forum.bricksbuilder.io/uploads/default/original/2X/f/fe0b07e25351669b2621387a6012abf3038a4bc5.png)

![image](https://forum.bricksbuilder.io/uploads/default/original/2X/2/2d2ef3546bf51800ea57964eb277cd0a56096a1f.png)

See that the div that should be hidden is still displayed in the html.

 ![image](https://forum.bricksbuilder.io/uploads/default/original/2X/0/03043ec0da1c496806ecad66559f0ea21fc41fc9.png)

I scoured the Facebook community and the Forum and found dozens of people facing the same issue.

I’m having a hard time believing this is user error.

---

<div class="post-metadata">

**Author:** ![andrespereirabr](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/andrespereirabr/32/2556_2.png) [@andrespereirabr](https://forum.bricksbuilder.io/u/andrespereirabr)\
**Post date:** [November 29, 2022, 5:23pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/8 "2022-11-29T17:23:06Z")

</div>

The problem is that the loop div should be hidden, and as the condition is applied on the child div (card), the parent div (loop) continues to be displayed in the html.

---

<div class="post-metadata">

**Author:** ![andrespereirabr](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/andrespereirabr/32/2556_2.png) [@andrespereirabr](https://forum.bricksbuilder.io/u/andrespereirabr)\
**Post date:** [November 29, 2022, 5:29pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/9 "2022-11-29T17:29:22Z")

</div>

When I apply the condition on the same element the loop is in, everything works perfectly! But it only works with native WordPress fields. Does not work with Metabox fields.

![image](https://forum.bricksbuilder.io/uploads/default/original/2X/f/ffed3ffde20e7ba8bce78b74e8637ee83b142b70.png)

![image](https://forum.bricksbuilder.io/uploads/default/original/2X/f/f23debf2fce73bbefcf8a44f5dc2ef02d7f218a9.png)

![image](https://forum.bricksbuilder.io/uploads/default/original/2X/f/f01738cd518915729fb79e21d0325303616a5dd5.png)

---

<div class="post-metadata">

**Author:** ![Tobias](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tobias](https://forum.bricksbuilder.io/u/Tobias)\
**Post date:** [November 29, 2022, 5:33pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/10 "2022-11-29T17:33:45Z")

</div>

Ah now I got it. Thanks for your explanation. The html code was meant.

Basically you can solve this via your loop and without a condition. You need a meta loop for this.

Inside of your loop add the meta query with your condition:

![Shared with CloudApp](https://forum.bricksbuilder.io/uploads/default/original/2X/4/45e3197c8110823e4a3faf9274587ad939f423ce.jpeg)

---

<div class="post-metadata">

**Author:** ![andrespereirabr](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/andrespereirabr/32/2556_2.png) [@andrespereirabr](https://forum.bricksbuilder.io/u/andrespereirabr)\
**Post date:** [November 29, 2022, 5:39pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/11 "2022-11-29T17:39:05Z")

</div>

Worked perfectly! Thank you very much! 🙏

Now I was still in doubt as to why the conditions didn’t work. Do you agree that there is a problem?

---

<div class="post-metadata">

**Author:** ![Tobias](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tobias](https://forum.bricksbuilder.io/u/Tobias)\
**Post date:** [November 29, 2022, 5:48pm UTC](https://forum.bricksbuilder.io/t/loop-and-condition/8102/12 "2022-11-29T17:48:59Z")

</div>

Usually when using a condition it should not exist in the source code.
