I have created a popup template that pulls dynamic data from a custom post type. I would like to have the popup only show if there is a published post in that CPT. If there are no published posts, the popup should not display at all.
I have added a condition to the outer element (section) in my popup template, which hides the popup content if there are no posts available. However, the popup backdrop still displays even though there is no content, and you have to click to dismiss it and browse the site. How can I completely disable the popup if there are no published posts?
Still looking for a solution to this. Is there a way to apply a condition to a popup template so that it only displays if there is a published post in the PopUp CPT that I created?
i don’t think there’s a normal way like condition or so to do this.
But maybe you can cheat it in.
Like, as posts are not shown on an empty query. You might be able to add a viewport trigger to some output of the query that’s then only shown when there is something to show.
So maybe you can have the query output some style element or even a empty text line with just a space or so, just to trigger the viewport trigger.
I haven’t tried it or so, but that’s what i would try.