I am trying to: filter my list of results to exclude those that have the custom field > checkbox selected.
Link to a page where the issue can be seen: hidden link
I expected to see: Only 1 test house that I have setup with the checkbox checked.
Instead, I got: No results found
If I setup a query filter to only show those that have the checkbox, so far it has worked properly. It's only now when I go to my other view and want to exclude the checked items from this list will it not display any results.
Hi Michael,
Thank you for waiting.
I performed some tests on my website with a similar checkbox field and the filter to include or exclude the posts, based on the field's state, and this worked as expected.
To confirm, if any custom field values were saved or not with your posts in the field "Ryder Cup ONLY" this test page "View: test view for house rentals" with a view to show the default and raw values, clarifies the situation.
( hidden link )
Please note how only one of your posts "Ryder Test House" actually has any value stored in the field "Ryder Cup ONLY" and the rest have no values at all. It suggests that these posts were added before the "Ryder Cup ONLY" field was configured as it is now (to store 0 when not checked). If you'll create a new test house rental post now, you'll see that 0 or 1 will be saved for the field, based on the checked/unchecked state.
The way WordPress custom field query works, it doesn't consider those posts, in which the target custom field's key doesn't exist.
To make this work, you'll either have to edit and save each post manually from its post edit screen, or you can create custom code that runs once, to programmatically get all house rental posts ( ref: https://developer.wordpress.org/reference/functions/get_posts/ ) and update the "wpcf-ryder-cup-only" field with a 0 as a value ( ref: https://codex.wordpress.org/Function_Reference/update_post_meta ).
I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar
My issue is resolved now. Thank you! Displaying the raw data was helpful for me to see why the queries were not filtering properly. I have since switched from a checkbox to a dropdown, but the same logic applies.
For those needing to bulk edit, I ended up finding this plugin : hidden link . This gave me a simple UI to be able to select all posts within my custom post type and update the custom fields as needed. Super helpful and fast! Worth the cost.
After bulk editing, I was able to update by queries to filter to the correct fields.