Hello. Thank you for contacting the Toolset support.
There is no such way to add custom custom toggle but I can help you with basic checkbox.
By default "AND" clause will be applied between multiple taxonomy terms.
With your view:
- hidden link
I've added the following custom filter for "And / OR" as checkbox:
<div class="form-group">
<label for="wpv-custom-or">[wpml-string context="wpv-views"]AND (Default) / OR[/wpml-string]</label>
<div class="form-check"><input type="checkbox" id="wpv_control_checkbox_wpcf-or" class="js-wpv-filter-trigger form-check-input" name="wpv-wpcf-or" value="OR" [set_field_checked url_param="wpv-wpcf-or" value="OR"] >
<label for="wpv_control_checkbox_wpcf-or" class="form-check-label">OR</label></div>
</div>
Where:
- As you can see the shortcode is added [set_field_checked url_param="wpv-wpcf-or" value="OR"] that will add the checked attribute when filter is checked.
I've added the following shortcode to "Custom Code" section with code snippet "toolset-custom-code" that will help us to make checkbox checked as we are using ajax :
add_shortcode('set_field_checked', 'func_set_field_checked');
function func_set_field_checked($atts, $content){
extract( shortcode_atts( array(
'url_param' => '',
'value' => '',
), $atts ) );
$checked = '';
if(isset($_POST['search']['dps_general'])){
foreach($_POST['search']['dps_general'] as $k=>$v):
if($v['value'] == $value and $v['name'] == $url_param){
$checked = 'checked="checked"';
}
endforeach;
}
return $checked;
}
I've modified the "wpv_query_filter" code as given under where I've adjusted the code for taxonomy relation "AND" and "OR" based on the checkbox selection:
add_filter('wpv_filter_query', 'func_hookin_shortcode_attribute_value', 99, 3);
function func_hookin_shortcode_attribute_value ( $query_args, $view_settings, $view_id ) {
global $WP_Views;
if( $view_id == 11727) {
$shortcode_attr_value = $WP_Views->view_shortcode_attributes[0]['wpvcategory'];
$query_args['tax_query']['relation'] = 'AND';
if(isset($_POST['search']['dps_general'])){
$checked = false;
foreach($_POST['search']['dps_general'] as $k=>$v):
if($v['value'] == 'OR' and $v['name'] == 'wpv-wpcf-or'){
$checked = true;
}
endforeach;
if($checked) {
$query_args['tax_query']['relation'] = 'OR';
}
}
$query_args['tax_query'][] =array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $shortcode_attr_value
);
}
return $query_args;
}
Can you please confirm it works as expected:
- hidden link