Forums › Forums › Search & Filter Pro › Show posts with no meta
- This topic has 2 replies, 3 voices, and was last updated 4 years, 9 months ago by Ross.
-
Anonymous(Private) March 19, 2020 at 9:28 pm #237281
Hi,
I created a form that includes post meta fields. I would like it to also include posts that do not have these meta keys at all.
It is especially a problem because one might use other fields to filter the results, but once the form is submitted the meta fields (range sliders in that case) are taken into account as well, and posts with no meta disappear.
I tried to use the “sf_edit_query_args” filter, but it seems the meta_query is empty when it is applied…
maybe I am using it wrong?Thank you very much!
Trevor(Private) March 20, 2020 at 7:39 am #237295You have correctly identified that this can be a issue. A similar issue is being discussed in this thread (and being looked at by Ross):
https://support.searchandfilter.com/forums/topic/range-slider-is-getting-triggered-by-default/
I have referred this thread to him, so that he can handle any other questions you have on this.
Ross Moderator(Private) March 20, 2020 at 11:36 am #237343Hi Erez
Unfortunately there is not real solution for this, once submitted sliders are added to the query, and all those without values will drop off.
The only solution really at this stage is to add a default value to your posts, for the sliders – eg
0
And then ensure your sliders ranges start from
0
.You can write a query to select all posts that don’t have your meta value:
https://developer.wordpress.org/reference/classes/wp_query/
https://wordpress.stackexchange.com/questions/80303/query-all-posts-where-a-meta-key-does-not-existAnd then loop through the results, adding default values for those post meta keys:
https://codex.wordpress.org/Function_Reference/update_post_metaI hope that helps.
Thanks
-
AuthorPosts