Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

hook_views_query_alter(&$view, &$query)

I can access the query ( var $query ) , and I can change either :

$query->where[0]['type'] 

to 'OR', or

$query->group_operator 

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 the desired result.

It seems changing those values, puts OR's everywhere, while I need => ( filter 1 AND filter 2 ) OR ( filter 3 ), so just 1 OR.

I could just check the Query of the View, copy it, modify it, and run it through db_query, but that's just dirty ..

Any suggestions ?

Thx in advance.

like image 903
Vodde Avatar asked Aug 27 '09 11:08

Vodde


People also ask

Is used for filtering content in Drupal?

The Content Management Filter is a contributed module that adds an easier way for administrators to filter the content on a Drupal site for administration purposes.

What are filters in Drupal?

The Filter core module allows you to configure text formats for processing text input for your site. These settings are under Configuration > Content authoring > "Text formats and editors" ( /admin/config/content/formats ).

What is contextual filter in Drupal view?

Contextual filters in Drupal allow you to add or remove information (content) to the currently displayed view. The filter acts dynamically based on the URL. If the provided argument value is in the URL, the view will contain certain results, if the value is not in the URL, the view will be filtered with other results.


1 Answers

If you are using Views 3 / Drupal 7 and looking for the answer to this question, it is baked right into Views. Where it says "add" next to filters, click the dropdown, then click "and/or; rearrange". It should be obvious from there.

like image 154
davidfurber Avatar answered Nov 07 '22 00:11

davidfurber