Hello
i have two select. One that shows Categories, and one with tags.
How can i do them NOT depening on eachother, or the resultview.
Scenario:
If i select one tag, the results changes - so far so good. But this also effects the select-dropdown contents.
If i select one tag, and if the result dont have any categories the select-dropdown with categories is empty until i reset the filter result. And tags disapare from the contetnt inside the selects-box.
how can i do so all tags and categories Always is shown ?
Hi,
Thank you for contacting us and I'd be happy to assist.
In your view's "View Search" block's settings, you'll see an option "Show only filter options that would produce results".
( example screenshot: hidden link )
Please disable that option and all categories and tag options will always be available.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks, found that. but what i mean is that they still interact with eachother as an condition.
If i have tag1 selected and change the category to cat 1 nothing is found becuse the post with Cat 1 dont have the "tag 1"
Do you understand me ? 🙂
Thanks for writing back and I apologize for the delay in getting back on this.
Your observation is correct and by default, the search filter for multiple taxonomies only brings in the results where all selected terms are attached.
To change this behavior so that results with "any" of the selected terms are shown, you can use "wpv_filter_query" hook.
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )
For example:
add_filter( 'wpv_filter_query', 'filter_tax_rel_fn', 1000 , 3 );
function filter_tax_rel_fn( $query_args, $view_settings ) {
if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 1234) ) {
if ( (!empty( $query_args['tax_query'])) ) {
$query_args['tax_query']['relation'] = 'OR';
}
}
return $query_args;
}
Note: You'll replace "1234" with the actual ID of your target view.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.