Hiding a section if an ACF Post Object is empty

Hi

I have a section on a single layout that contains a posts element with the looper provider set to dynamic content and the input as the dynamic content for a ACF Post Object {{dc:acf:post_field field=“recommended_offers”}}.

It all works as expected but some pages have content in the Post Object and some don’t so I’m now trying to hide the entire section if the Post Object field is empty.

Is there a way of setting up the conditions to check if the contents of a Post Object is empty and hide the section?

Thanks

Hello @sarammog,

Thanks for writing to us.

You can use the conditions type as a string and then insert the dynamic content code to compare the value. Please have a look at the given screenshot below.

In case you have not seen the doc on conditions and assignment, please have a look at it to learn more about how to set the conditions.

Hope it helps
Thanks

Hi

This is the first thing I tried but it seems to hide everything regardless of whether there are posts selected in the Post Object or not. Is this something to do with is being a Post Object and not a text field?

Hello @sarammog,

I tried to access your site dashboard, but the given login credentials are not working on my end. Please recheck and send us again.

Thanks

Sorry typo. Those details should work now.

Hey @sarammog,

Since your ACF field returns post objects and you are using it with your Looper Provider, you can utilize the “Provider Output IS NOT Empty” condition. I would recommend that you move your Looper Provider to the Section element instead. The Looper Consumer remains as is in the current element it is IN.

I have applied the above solution to your layout. Check out the secure note below to view the sample post items with and without the Recommended Offers:

  • See the secure notes.

Best Regards.

That is perfect. Thanks for all your help.

You are most welcome, @sarammog