You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to suggest the ability to return a dummy post object (not corresponding to any existing post) as a fallback for a query (in the query builder) if no items match the query. This may seem bizarre and unnecessary but here's my use case which I think is not too uncommon and I can't figure out a sane alternative solution.
Specific use case:
Case in point:
I have two different post types and two different queries for selecting specific posts from each of those types. Then I have a merged query because I want to display the matching posts in a single listing grid. However, when one of the queries does not return any matching posts I want to be able to display some static placeholder item in place of where the posts from that post type would have been.
For example, let's say I have a post type called "regular classes" whose posts correspond to weekly classes but each post is tied to a "topic" that runs for some weeks. I have a query that find the first upcoming class and returns just it.
Then suppose I have another post type called "special classes" whose posts correspond to classes that run occasionally on specific dates and each one is distinct. I have a query that returns all upcoming special classes.
Then I merge those queries and display them in a single listing grid (where the template of the grid obviously uses some conditional visibility based on post type). So that I have item 1 as the "regular classes" that shows some info specific to the first upcoming class, and all other items in the grid are all the special classes.
Goal:
So far ok? Now, if there is a time when there aren't any confirmed scheduled regular classes, that query would return no items and so the listing grid won't display anything from that post type, and only special classes if any will show. In that case I want to display a generic placeholder that says "regular classes" or something.
Alternative workaround?
I cannot think of how to do this currently apart from a convoluted workaround that creates a dummy post of "regular classes" type, somehow (maybe using a switch field) is marked as a dummy and then have the "first upcoming regular class" query also match "dummy" classes... Sounds confusing and prone to errors.
Suggested feature as a solution:
So what came to my mind is having an option for query to return a blank post object (all fields empty/zero) in case no actual posts match it. Then the listing grid template just needs to set some fallback values for dynamic fields or use conditional visibility based on whether the post ID is non-0 and can still have an actual item in the grid but with fallback static content.
I hope this makes sense.
The text was updated successfully, but these errors were encountered:
@aayla-secura
You can create a component that displays what you need, then add this component to the page and use Dynamic Visibility (show if Query Has Not items) and a listing grid display if Query Has Items
Hi there @Crocoblock , thank you for replying. Unfortunately this solution does not work for me, since I need the listing grid, which displays a MERGED query to always be shown. One of the two merged queries always has items to display, but the other one may or may not. And I want to insert a static fallback for that sub-query only, but still have it as part of the main listing grid. I hope this makes sense.
Unfortunately, we do not plan to introduce such functionality into our plugin. Now, our team is working on more priority tasks. However, in the future, we will not exclude the possibility of adding this functionality to the core of our plugin.
But you can do it with an additional custom code
With this filter, you can check if Query returns an empty array you can add a virtual post with ID 99999999 and then use dynamic visibility
The feature request:
I'd like to suggest the ability to return a dummy post object (not corresponding to any existing post) as a fallback for a query (in the query builder) if no items match the query. This may seem bizarre and unnecessary but here's my use case which I think is not too uncommon and I can't figure out a sane alternative solution.
Specific use case:
Case in point:
I have two different post types and two different queries for selecting specific posts from each of those types. Then I have a merged query because I want to display the matching posts in a single listing grid. However, when one of the queries does not return any matching posts I want to be able to display some static placeholder item in place of where the posts from that post type would have been.
For example, let's say I have a post type called "regular classes" whose posts correspond to weekly classes but each post is tied to a "topic" that runs for some weeks. I have a query that find the first upcoming class and returns just it.
Then suppose I have another post type called "special classes" whose posts correspond to classes that run occasionally on specific dates and each one is distinct. I have a query that returns all upcoming special classes.
Then I merge those queries and display them in a single listing grid (where the template of the grid obviously uses some conditional visibility based on post type). So that I have item 1 as the "regular classes" that shows some info specific to the first upcoming class, and all other items in the grid are all the special classes.
Goal:
So far ok? Now, if there is a time when there aren't any confirmed scheduled regular classes, that query would return no items and so the listing grid won't display anything from that post type, and only special classes if any will show. In that case I want to display a generic placeholder that says "regular classes" or something.
Alternative workaround?
I cannot think of how to do this currently apart from a convoluted workaround that creates a dummy post of "regular classes" type, somehow (maybe using a switch field) is marked as a dummy and then have the "first upcoming regular class" query also match "dummy" classes... Sounds confusing and prone to errors.
Suggested feature as a solution:
So what came to my mind is having an option for query to return a blank post object (all fields empty/zero) in case no actual posts match it. Then the listing grid template just needs to set some fallback values for dynamic fields or use conditional visibility based on whether the post ID is non-0 and can still have an actual item in the grid but with fallback static content.
I hope this makes sense.
The text was updated successfully, but these errors were encountered: