Open
When multiple search filters or query filters are added to a View, the legacy editor for Views allows you to specify whether the condition for matching multiple filters should use AND or OR. (The option isn’t currently available in the block editor.)
Selecting OR doesn’t work, the generated query always applies AND as the condition for multiple filters.
It would be possible to modify the query generated by Views to force the OR comparison using the API filter wpv_filter_query, with a suitably high priority (e.g. 101). See https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
An example of the kind of code that can be used to switch the default AND comparison to OR would be:
function tssupp_filter_query($view_args, $view_settings, $view_id) { if (in_array($view_id, array( 117 ))) { // Edit View ID(s) if ( isset( $view_args['meta_query']['relation'] ) ) { $view_args['meta_query']['relation'] = 'OR'; } } return $view_args; } add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);
Any word on getting this fixed? It’s been over 7 months.
Why is this still an issue? Views is a query engine that only supports AND queries? Come on folks…
This would be helpful. Sadly, the workaround above doesn’t work for all query filters.
e.g. Filter by post relationship or repeatable fields group owner OR Post author filter