Skip Navigation

[Resolved] How to search for value in a range

This support ticket is created 4 years, 3 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 1.78 hours from now. Thank you for your understanding.

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: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 4 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1449609

I want to have a price search where the user can search for example for price between 5000 and 10000. I'm new to Toolset and don't see any way to do it?

#1449967

Hello,

It is possible with custom field filter, see our document:
https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/
section "Comparison function":
BETWEEN Two values Checks if the custom field value is between the two compare values

#1451291

I don't think you understood quite right. I want the user to be able to search for prices that fall in an amount range. For example: I have 5 items priced 100,150,200,250,300. I might want to have a search dropdown select where they can pick any,100-200,200-300. Or assuming you can't do it that way in Toolset - how about two search fields - one for price from the other for price to so you could enter 200 and 300 and you'd get the 200, 250 and 300 items. If you could pick the price field twice in search fields you could do this using is greater than or equal and is less than or equal but it only lets you pick price once.

#1455297

Thanks for the details, it needs custom codes, for example this thread:
for example, you can setup the selector "price-range" option values as below:
- All: 0 - 999999
- 0-100: 0-100
- 100-200: 100-200
- 200-300: 200-300
...

Then use Views filter hook wpv_filter_query to trigger a PHP function, in this PHP function:
1) get the URL parameter value of "price-range",
2) explode the value to an array using separator "-"
3) Apply above array value into View's field query

More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
compare (string) - ... 'BETWEEN',

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.