Hi, I would need to create a dropdown filter for price, like this:
- Less than 20.000
- From 20,000 to 80.000
- From 80,000 to 120.000
- Over 120.000
I tried to search in the previous topics, but I couldn't.
Can you give me a hand? Thanks.
Hello and thank you for contacting the Toolset support.
If you would like to search by min price and max price, you can implement it using the user interface, but, if you want to filter using custom price ranges, you will need some custom code.
First, you need to add the price dropdown using shortcodes, as you will be passing the dropdown labels and values inside the shortcode. Using the values and display_values arguments of the wpv-control-postmeta. Read more about the shortcode here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-520693
Then, you will need to alter the view's query to introduce the price comparison by hooking into the view's wpv_filter_query filter.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
When displaying a view, this filter is applied to the arguments being generated by the view's settings before they are passed to the WP_Query class.
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
You can check similar cases on the following tickets:
- https://toolset.com/forums/topic/need-help-implementing-woocommerce-price-range-filters-to-views-archive/
- https://toolset.com/forums/topic/custom-search-filter-price-range-dropdown/
I hope this helps. Let me know if you have any questions.