views_query_alter change to operator OR for contextual filters and normal filters


Download and install the module Views arguments in filters. It is a sandbox module so you will have to use git.

In your view, remove your contextual filter and replace it with a global null contextual filter.

enter image description here

Then add the filter that you want as the contextual filter to the normal filter area in views, and in its value argument set the value as %1 (ie you are ferencing the global null contextual filter).

enter image description here

Now rearrange the filter and-or groups to your liking.

enter image description here

As a simple try to help, did you implement hook_views_query_alter(&$view, &$query) as following ?

First, call Views API in YOUR_MODULE.module :

 * Implementation of hook_views_api().
function YOUR_MODULE_views_api() { 
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'YOUR_MODULE_NAME'),

Create a file It seems that with Views, you don't need to put files[] = in your module's .info file, as you usually would.

Then implement hook_views_query_alter() in

function YOUR_MODULE_views_query_alter(&$view, &$query) {

  if($view->name == 'VIEW_NAME') {

    //at this point find the right part to alter and adapt following line
    $query->where[0]['type'] = 'OR';


EDIT: If for any reason, you can't override the View with hook_views_query_alter(), Views Filter Harmonizer might fit your need.

Views Filter Harmonizer solves an operational foible with the Views module regarding filtering. This small module allows you to have a contextual filter argument apply only when there is no corresponding regular (exposed) filter value present.

Last, check also Views arguments in filters sandbox, or test this patch. Both rely on the same logic, setting a "Global: Null" contextual filters and using it in regular filters. Many people report using it to solve the same And/Or contextual filters issue. Good luck !

Tags: Views / Database

Similar questions

drupal 7 views_query_alter if field empty sort with another field
i have a view that show all contents of type NEWS NEWS has like fields : Content = Title Scheduler = publish-on and in sort criteria : i want sort contents with two option : With scheduler (publish-on = DESC) and With post date i want sort content with scheduler, and when scheduler field is empty he sort with post date i have created hook views que...
drupal contextual filter (URL argument) OR operator
So, I have a view which filters content from 3 different content types: Books, photos and articles and outputs in the same view. All three content types have an independent "issue number" field. The view basically filters content based on the issue number. Now in order to create views for each issue, I was individually creating views for each issue...
Drupal facets relevance sorting - change Solr query operator from "AND" to "OR"?
How to change drupal facets solr query operator from "AND" to "OR"? We're working on a drupal based Job Board and want our faceted search to provide results that match parts of selected facets. E.g. the query has the facets "facet1", "facet2", "facet3", "facet4" - all from different taxonomies and thus in different facet blocks standard behaviour i...
What are the conditions for the "is one of" operator being enabled for filters on a particular field?
When I am creating a filter on a field, the "is one of" operator is not available. What are the necessary condition for the "is one of" operator to be available for field. I have seen an example in which the "is one of" operator is available for taxonomy values. What is it about taxonomy values that make the operator available for them?
OR operator in Drupal View Filters
I need to implement an OR operator between some filters in a Drupal View. By default, Drupal AND's every filter together. By using I can access the query ( var $query ) , and I can change either : to 'OR', or to 'OR' The problem is however, that I do not need OR's everywhere. I've tried changing both of them to OR seperately, and it doesn't yield t...
How do we use two contextual filter because when i use two contextual filter it only filter from first filter second contextual filter is ignored
I have a view with two contextual filters I want to filter from both filter but it only filters by the first contextual filter. The second contextual filter is ignored.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.