I am trying to show all properties which has bedrooms greater than equal to the selection made by the user in the search bar of a view. Here is the page: hidden link
Bedrooms is a custom toolset field and i have been using
to display values.
This is my settings in the view. Check this screenshot: hidden link
When i debug the query, this is how Toolset is using a COMPARE = IN and it should be ">=" . I have uploaded an image for this.
Check the attachment
Could you please confirm whether the same problem occurs if you output the filter as a select dropdown instead of as checkboxes?
I suspect the issue may relate to how checkboxes are handled, and if you can confirm the problem doesn't occur with a select dropdown that will narrow down what to look for.
I just created a test site to check for myself, and it works correctly with a select dropdown, but not with checkboxes.
Note that I used the New Filter button to insert the filter markup, which generates a wpv-control-postmeta shortcode rather than a wpv-control shortcode.
With a select dropdown the generated query is correct, as can be seen in the first screenshot.
When I edited the filter and changed it to use checkboxes as the filter input then the comparison used IN, as you describe. (See second screenshot.)
But I would say this is expected. A checkboxes filter allows the user on the front end to select multiple values, and it makes no sense to filter posts using a comparison such as >= when using multiple values for the comparison.
So I'd say there is perhaps a usability issue that the dialog lets you insert a checkboxes filter and try to specify such a comparison when under the hood it realizes that makes no sense and automatically sets the comparison to IN.
I think that when we are custom defining, this should not be the case. Anyways, do you have a snippet where i can just change meta query to use >= operator ?
It's not so simple as switching the compare parameter because the value passed by a checkboxes filter is different than the value passed by a select filter (an array of values rather than a single value), even if only checkbox is actually checked.
It is meaningless to compare post field values to an array of values with a mathematical operator such as ">=", so even if I provided a code snippet to change the compare parameter to ">=" from "IN" it wouldn't work.
If you want to have a compare parameter like ">=" then you must use a filter type that provides a single value, e.g. a select dropdown.
Hello there! I wanted to add that you can also display the filter as radio buttons, which will produce only one value, and would be treated like the dropdown. I think that it could be a good solution for this case.
I agree with Nigel, checkboxes are meant to return an array of values instead of only one.