Skip Navigation

[Resolved] Seting a filter by price range

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

Problem:
How to implement filter with custom price range.

Solution:
When you try to add the view's filter it will give you option to add "Dropdown" options manually. Please check the following image for reference:
=> https://s.nimbus.everhelper.me/share/1193380/iotu5wq8etf10ukakf0p

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/seting-a-filter-by-price-range/#post-581032

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

0% of people find this useful.

This support ticket is created 6 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 4 voices.

Last updated by Chris 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#580981

I am trying to set a filter by price range for properties

The display values will be: 130.000 - 150.000 €, 150.000 - 180.000 €,180.000 - 200.000 €
I don't know what I should set in values, as I create the price field with a number
I don't want to display a view that show price min and price max but a range of prices in a list

I want someting like this : hidden link

Thanks

#581032

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - to build such price range filter, you need to add filter options manually.

When you try to add the view's filter it will give you option to add "Dropdown" options manually. Please check the following image for reference:
=> hidden link

For example:

<div class="form-group">
	<label>[wpml-string context="wpv-views"]Number of pages[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-FIELD-NAME" type="select" source="custom" url_param="wpv-FIELD-NAME" values="130000-150000,150000-180000,180000-200000" display_values="130.000 - 150.000 €, 150.000 - 180.000 €,180.000 - 200.000 €"]
</div>

Where:
- Replace "FIELD-NAME" with your original field name.

Now, further you need to use view's hook "wpv_filter_query" to apply the range properly.

For example:

add_filter('wpv_filter_query', 'search_between_numeric_func', 90, 2);
function search_between_numeric_func($query, $setting) {
    if($setting['view_id'] == 99999) {
       // your code goes here
    }
    return $query;
}

If you do not know how to do it, I will be happy to help you further. You should setup your range filter as I suggested above and I'll be happy to help with "wpv_filter_query" part. For that I need problem URL and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#956339

Hi Minesh, could you helpme?

I have exactly the same requeriment, I do the firts part and i get this filter

[wpv-control-postmeta auto_fill_sort="asc" auto_fill="wpcf-precio" auto_fill_default="Precio" field="precio" type="select" source="custom" url_param="precio" output="legacy" values="0-100000,100001-200000,200001-300000,300001-400000,400001-500000,500001-99999999999" display_values="Hasta $100000 ,$100001 - $200000,$200001 - $300000 ,$300001 - $400000 ,$400001 - $500000 ,Más de $500 000"]

I copy de the code

add_filter('wpv_filter_query', 'search_between_numeric_func', 90, 2);
function search_between_numeric_func($query, $setting) {
if($setting['view_id'] == 99999) {
// your code goes here
}
return $query;
}

in the functions.php

But in front I dont get any data in dropdown

#957447

Hi there, same problem here, is there anyway you can give an example of how the code inside the hook will look like? the info on the documentation is amazingly vague.

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