Tell us what you are trying to do?
I'm trying to add a price range filter to a views archive. My post type has a custom field which is numeric and I want to have a filter that uses price ranges like:
0-100
100-200
200-500
500-1000
1000+
Is there any documentation that you are following?
There are several help topics covering this but none really give a comprehensive way to make it work. This one seems to get me the closest to success, but not quite there.
https://toolset.com/forums/topic/need-help-implementing-woocommerce-price-range-filters-to-views-archive/
Right now I have the following:
My field slug is wpcf-course-price
My Custom Field Filter is:
Select items with field:
Course Price is a string between URL_PARAM(wpv-wpcf-course-price), URL_PARAM(wpv-wpcf-course-price)
My Filter is:
<div class="form-group">
<label>[wpml-string context="wpv-views"]Price[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-course-price" type="radios" source="custom" url_param="wpv-wpcf-course-price" values="0-100,101-200,201-300,501-1000,1001-9999999" display_values="0-100,100-200,200-500,500-1000,1000+"]
</div>
My js in functions.php is:
add_filter('wpv_filter_query', 'search_between_numeric_func', 90, 2);
function search_between_numeric_func($query, $setting) {
if($setting['view_id'] == 20105) {
foreach((array)$query['meta_query'] as $k=>$v):
if(isset($v['key']) and $v['key']=='wpv-wpcf-course-price'){
$values = explode(",",$v['value']);
if(count($values) > 1){
unset($query['meta_query'][$k]);
foreach($values as $x=>$y):
$query['meta_query'][$k][$x]['key'] = 'wpv-wpcf-course-price';
$query['meta_query'][$k][$x]['type'] = 'NUMERIC';
$query['meta_query'][$k][$x]['compare'] = 'between';
$query['meta_query'][$k][$x]['value'] = str_replace("-",",",$y);
endforeach;
$query['meta_query'][$k]['relation'] = 'OR';
}
}
endforeach;
}
return $query;
}
Right now my radio buttons display but whichever selection you click give no results.
I'm aware that the js above is set up for a multi-select / checkboxes setup, but I think it should work for a dropdown or radiobuttons setup as well.
I also thought I might have needed a numeric field instead of a text field so there's one set up - "wpcf-course-price-number". But I don't seem to get any better results using this.
Is there a similar example that we can see?
I think there are many sites that use this kind of filter but I don't know of any Toolset ones.
What is the link to your site?
enlace oculto
Thanks in advance for your help.
Tim