Skip Navigation

[Resolved] Use < and > in a filter

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to be able filter a numeric field in a custom search View using predefined ranges and single values, like "less than 5", "5", "6", and "more than 6".

Solution: This exact type of complex range filtering isn't possible to achieve in a View without custom code. However, it is possible to include one "between" filter that allows a minimum and a maximum value. Users can specify a range of values, or leave either value empty, to see the matching results.

Relevant Documentation:

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

Our next available supporter will start replying to tickets in about 2.42 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Stina 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#626423

I am trying to filter a field with numbers into four choices:

<label>[wpml-string context="wpv-views"]Antal personer totalt[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-antal-personer-totalt" type="checkboxes" source="custom" url_param="wpv-wpcf-antal-personer-totalt" values="<5,5,6,>6" display_values="4 platser eller färe,5 platser,6 platser,7 platser eller fler"]

Link to a page where the issue can be seen: hidden link

I expected to see:
o 4 platser eller färre
o 5 platser
o 6 platser
o 7 platser eller fler

Instead, I got:
o 5 platser
o 6 platser

What am I doing wrong?
Stina

#626773

Hi, it looks like you have several different "range" style comparisons in a single filter. This type of complex filtering isn't currently supported in Views and would require custom code. You can use one comparison like "less than", "greater than", "equal to", "in", "not in", "between", and so on in a single filter, but unfortunately it's not possible to combine multiple "between" comparisons in a single filter like this.

To create a custom filter control that filters between dynamic value ranges like this, you could implement the wpv_filter_query filter as described in the documentation here: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

One alternative that is currently possible in Views is to use just one "between" filter. The filter will show two input fields. Your users can set a maximum and/or a minimum value and see the matching results.

#627476

"One alternative that is currently possible in Views is to use just one "between" filter. The filter will show two input fields. Your users can set a maximum and/or a minimum value and see the matching results."

That solved my problem, thank you!