Skip Navigation

[Resolved] Comparing values by meta query is using 'IN'operator and not '>=' as defined in

This support ticket is created 3 years, 2 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.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 7 replies, has 3 voices.

Last updated by amrinderS 3 years, 2 months ago.

Assisted by: Jamal.

Author
Posts
#2159165
Capture.PNG

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

 [wpv-control type="checkboxes" field="wpcf-number-of-bedrooms" display_values="1+,2+,3+,4+" values="1,2,3,4" url_param="wpv-wpcf-number-of-bedrooms"]

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

#2159601

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

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.

#2159625

Hello Nigel,
Glad you are on this ticket.

Yes just tried with select and again same COMPARE = "IN" is being queried.

This seems to be a bug with Toolset. Also i am using this shortcode

[wpv-control type="checkboxes" field="wpcf-number-of-bedrooms" display_values="1+,2+,3+,4+" values="1,2,3,4" url_param="wpv-wpcf-number-of-bedrooms"]

Thanks

#2159743

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

checkboxes.png
select.png

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.

#2159771

Hey Nigel,

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 ?

#2159885

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

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.

#2159895

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.

#2160055

Thanks Nigel and yes Jamal,
Already tried with radio buttion and it worked.

My issue is resolved now. Thank you!