Loop and condition

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? :thinking:

1 Like

Thank you for this question. Looki also for a solution for a while >> ACF True/False = Show/Hide Custom Post Type Condition

@timmse please see this.

Working with Metabox.

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

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.

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

And the condition on the card would be like this:
Shared with CloudApp

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

1 Like

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

image

image

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

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.

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.

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

image

image

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

1 Like

Worked perfectly! Thank you very much! :pray:

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

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

2 Likes