Hi
I am using a plugin to import posts but it doesn't set a field that is a tick box.
As its not configured to update this, Toolset doesn't seem to store the unchecked value until I go in and edit the post, which I wont do often.
I want to filter by this field to exclude ones which are CHECKED. However when I create a filter to exclude ones where the value is 1, nothing shows up because its as no value at all. I would think if it has no value therefore it isn't equal to 1.
Any ideas?
Thanks
Hi,
Thank you for contacting us and I'd be happy to assist.
The way custom field query works in WordPress, it only considers those posts which have at least one custom field record attached with the target custom field's key.
This means that if you're filtering by a custom field for example "field-a", only those posts would be considered which have:
- some value stored with the key "field-a"
- 0 saved as a value with the key "field-a"
- empty or no value is saved with the key "field-a" (but a custom field record exists with this key)
In other words, any post where there is no custom field key record for the "field-a", it will be ignored.
This where the "When unchecked, save 0 to the database" option in the checkbox type custom field's settings, comes in handy.
( example screenshot attached )
Please note how I've set the field to save 1 when the checkbox is checked and 0 when it isn't checked.
Similarly, if you're importing the posts, you'll need to make sure to save 0 for this field, for the unchecked state.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar