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?