Hide section when looper provider does not return a result

I usually have featured posts that I want to display prominently on my homepage. I have set up a section as looper provider, an in this section I have a div as looper consumer, the elements in their (with their beautiful styling) draw their dynamic content form the desired featured post(s)). This all works fine.
What I cannot get to work: Sometimes, I do not have a featured post, and then I want this whole section not being displayed. Basically: If the looper-provider returns nothing (an empty array, I guess), then I want the complete section not being displayed. I thought I could get this to work with “conditons” on the section (or the div), but I cannot figure out how it works.
Thsi is with Pro 4.0.11
Thank you!

Hi @striata,

Can you please provide login credentials for your site in a secure note to examine the settings you have made, including:

– WordPress Site URL & Login URL
– Specific Page URL where you have made the settings
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

Thanks! See secure note above.

Hello, @striata! Thanks for writing in…I can totally see what you’re going for here and I think it’s a great idea. If you have no results from your Looper, it’d be great to be able to either hide it completely or swap it out with some other form of content to give the user some feedback. As of this moment, we do not have a condition that meets this exact situation in the Element Conditions, but I have created an issue for in our GitHub account to look into this at some point. Thanks!

@kory, thank you for looking into this, I am looking forward to this feature!
The idea (in my case) is to have a stylized section on the homepage that highlights an upcoming featured event - if there is one. At the moment, I have to manually show/hide the section. That means one has to adjust the page itself, rather than just changing the tags of a post. With this feature in place, one could just simply flag a post as “featured”, and the section shows up. Remove the flag, and the section on the homepage magically disappears. This would be awesome!
Do you have any ETA on that? You currently have relatively complex conditions that can be checked; it seems adding an “empty” condition should not be that complicated. Of course, I have no idea what is going on behind the scenes.
Thank you, by the way, for the great tutorial videos! Will there be more info on the “Query string” feature - such as appropriate syntax, etc? When knowing the sytanx, it would be easier to write own queries that are currently not met by the other options.
Thanks again!

Hi @striata,

I’m sorry, we don’t have an ETA. We’re working on a shorter cycle that will be available in a couple weeks. I’ll see if we can explore it for that release. I can also message you here when it’s ready and send you a development build with the feature if you want to play around with it.

To clarify on how it will work, there will be a new condition based on if a looper is empty or not. However, you’ll only be able to use it on elements that are children of the Looper. Unfortunately that means you may have an empty section element. When an element is rendered, the element conditions run before loopers are setup. I’m going to investigate if there’s a way around this but I’m note sure at the moment if it will be possible. At the very least, you could make sure the Section has no styling (padding, background, etc.) and place a Div inside the Section to style instead.

I wish we had more to offer on the Query String. I think that method of building a query is somewhat of a leftover WordPress relic because sometime in the past year or so they removed all reference to it from their documentation. It still works, but there’s not even a WordPress resource I can link you to.

1 Like

Thank you! Keep up the great work!

Thanks! Appreciate your support, @striata!

Hi @striata,

Good news! We built this condition out today and it will be in the next release. I was also able to reorganize the element lifecycle so conditions run after a looper is initialized. This will let you hide an element that has a looper provider with no results. Expect to have access to it within a couple weeks as Pro 4.1 is going to be a smaller followup cycle to make improvements just like this one to Pro 4.

Absolutely fabulous! Thank you very much.
So the only thing I am really missing now is looping over ACF repeater fields… (this has nothing to do with the topic of this thread)
Thanks again!

You are most welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.