Hide Div if query is empty

Hello

On my single product page, I’ve a div that contains the elements “related posts” and “basic text”.
The “related posts” is a query loop that shows Woocommerce products in a similar category.

How can I hide the div completely if the query returns no products? (It’s about hiding the “Basic text” element as well).

I’ve tried several “conditions” without success.

I’d be glad if someone can help me out.

Thanks

1 Like

I don’t know if this will help or not, but here is an example from a video (from a membership site).

In this example it is using custom fields to inject dynamic data, and the developer has put “show” and “hide” as radio button options in the custom fields, so that if the user sets a dynamic data entry to “hide,” the entire section will not appear.

Your situation is different as you would seem to need to identify all of your product images with something the condition could look for, and not show the container if that “something” does not appear.

(“hide” here is not a command to hide, but a data field selected by the user that does or does not appear)

show_hide_container_condition_example

Thanks for your suggestion, I’ve tried something like that but with no success.

Hey all, I found a solution online, in case it helps someone.

I have used this approach and it works like a charm :slight_smile:

5 Likes

Hey @matt-cnc , thanks for sharing this.

I finally managed to hide a “Related Files” block consisting of ACF repeater fields using the Query Results Count method from BricksLabs.

I wish we could do the same without the need to hunt down the element’s ID though. It would be nice if we could achieve the same condition via the Conditions Bricks UI by using the dynamic data dropdown and selecting one the ACF repeater fields that we know that if it is empty, then the section, block, div should not render.

By the way, does anyone know if there is a feature request for this?

how would we do this with the new components? as they don’t carry ID’s anymore and converted to classes

Conditions are not looking for HTML IDs, they’re using inner Bricks IDs

Setting a condition to the targeted block element worked for me guys I hope it is helpful. (The change only appears at frontend)

1 Like