Posts Query returns -1 posts instead of 0 posts if "Post In" current meta field value is empty
Closed this issue · 1 comments
Describe the bug
I have a meta field for my homepage named "Posts to show".
Its datatype is "Posts" and "Multiple" is set to "True".
This allows me to show specific posts on my homepage which have been selected:
Three posts selected and saved as a metafield to the homepage
To get the selected posts to show on the front-end, I use a Posts Query:
And the result is this:
The three posts selected and saved to the meta field are shown on the front-end
The issue I'm having is when no posts are selected in the meta field. If no posts are selected, you would expect no posts to load on the front-end (0). However, the opposite happens and ALL posts will show (-1).
For example, here is the meta field with no saved posts:
And here is the front-end:
As you can see EVERY post is displayed instead of none.
This is a bit of a nightmare when it comes to editing in Elementor as if there are a lot of posts, I cannot edit the template with the list grid widget as there are too many posts to load. Not just this, but it means I have to create a separate metafield (switcher) to manage hiding it as the option to hide the listing grid widget if the query is empty, doesn't work.
If no posts are saved in the meta field, the query should return 0 posts, not all of them.
To Reproduce
Steps to reproduce the behavior:
- Using JetEngine, create a metabox for a page or a metafield for a CPT.
- Make this field a "Posts" field and allow Multiple.
- Ensure you have many posts saved.
- Select just some of these posts in your newly created field.
- Create a query to display these saved posts.
- Create a listing grid for posts.
- On the page with the meta field assigned, add a listing grid with the custom query.
- See how it appears with posts saved (just fine) and without any posts saved (it returns all posts).
Expected behavior
If no posts are saved in the Posts meta field, the listing grid should return 0 posts ("No data was found message") rather than all of them.
Hi @Dudeney95
You need to set Fallback
. For example 'none'
https://i.imgur.com/9eXpIDK.png