This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have a checkbox that saves 1 to db. (not 0 if not checked)
Now I am trying to filter a view to show only posts that does not equal 1, on this field.
I want to display all posts that have not checked this box.
Problem is that most existing posts have no post meta for this field so I only get a blank result in the view.
Tried string ne 1 and number ne 1.
Also tried lt 1.
In words I'm asking WP to return posts where the wpcf-yay-or-nay field does not equal 1 (which is the value stored in the database when the field is checked).
WordPress will only return posts where the key exists and is not equal to 1.
So a solution would be to save 0 to the database if it is not checked, which would then work, but doesn't help if you already have lots of posts published that you would need to edit and re-save.
It wouldn't be too difficult to write a script that you run once (Code Snippets plugin is ideal for this) that loops over the posts, checks if they have the meta key present, and if not creates it with a value of 0.
Alternatively, you could modify the query using wpv_filter_query so that it returns posts where the meta value is not 1 whether it exists or not. This relies on a trick which is described in this SO answer: https://wordpress.stackexchange.com/a/81831/35739
I posted a long time ago that it would be great to get a 'Not Exists' option in the Views Query Filter. But It hasn't been implemented yet.
Any news on that?