Views 3: use logical-OR condition between Contextual Filters

Public

By default, Views uses the logical-AND operator for inserting all the contextual filters inside the 'WHERE' clause in the SQL statement of a view, This simple code uses hook_views_query_alter() to implement a logical-OR operator between contextual filters.

The module must have 2 separate source files:
a) MODULE.views.inc:

Get raw version
php
  1. <?php
  2.  
  3. function MODULE_views_query_alter(&$view, &$query) {
  4. // Whatever your view is named...
  5. if ($view->name == 'my_view') {
  6. $query->where[0]['type'] = 'OR';
  7. }
  8. }

b) MODULE.module:

Get raw version
php
  1. <?php
  2.  
  3. function MODULE_views_api() {
  4. return array(
  5. 'api' => 3,
  6. );
  7. }

Comments

Dake's picture

Thanks!