Tell us what you are trying to do?
1. Go to hidden link
2. Select "Plant Nutrition" under "Filter by Product Type" drop down.
3. Check "Nitrogen (N)". See the result count is 207.
4. Check "Application: Foliar". See the result count is 255.
If I set "equal to" in query filter, it should be OR , right?
It seems like it will filter as AND. (If I select 2 checkbox, it should decrease the result count.)
I even tested "in", I got exactly same result.
Is there any documentation that you are following?
https://toolset.com/forums/topic/filter-with-custom-field-checkboxes-that-compare-using-or-instead-of-and-in-view/
Is there a similar example that we can see?
No
What is the link to your site?
hidden link
Hi there,
It seems to be more of a problem related to this issue:
https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/
Would you please follow the workaround and see if you get the correct results?
Thank you.
I have been set up like that already.
Ok thank you. I checked with my colleagues and the default behavior for the checkboxes filter between the items of the checkboxes is AND.
If you want to change it to OR then you need to use the wpv_filter_query Toolset hook. For more information:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
There is a code sample that you can use and change the parameters according to your needs:
https://toolset.com/forums/topic/parametric-search-keeps-displaying-wrong-results/#post-357800
Thanks.
So I was thinking opposite around. So
[ ✓ ] Option A
[ ✓ ] Option B
[ ] Option C
Currently, either Option A and Option B show up. (OR)
I want to filter result to be shown if both Option A and Option B is selected (AND).
But it seems like filter is using OR by default.
Hi there,
You are correct, I double-checked and it is OR. Sorry for the wrong answer.
From what I understand you still will need to use wpv_filter_query hook to change the default behavior.
Thank you.
It seems like the structure of the query might changed from example you provided.
But I modified it and worked now.
Thanks you for your help and input!
add_filter( 'wpv_filter_query', 'we_custom_search_criteria', 101, 3 );
function we_custom_search_criteria( $query_args ,$view_settings ) {
$view_id = 3142; // set view id (wpv_view_count)
if ( isset( $view_settings['view_id'] ) && $view_settings['view_id'] == $view_id ) {
foreach( (array)$query_args['meta_query'] as $k => $v ) :
if( isset( $v['relation'] ) && $v['relation'] == 'OR' ) {
$query_args['meta_query'][$k]['relation'] = 'AND';
}
endforeach;
}
return $query_args;
}
My issue is resolved now. Thank you!