Last updated by Alice Heaton on Mon, 2008-10-27 08:52
I want a View query to capture nodes that may have the following three combinations of taxonomy terms:
a, b, c
The resulting logic should return true when "(b OR c) AND a"
The closest I have been able to get with Views are the following results:
- Returns (a, b) and (a, b, c) combinations
- Returns (a, c) and (a, b, c) combinations
Can anyone point out how Views filters should be configured for the results I need? The tutorials for Views seem to be lacking a reasonable explanation of how filters operate.
As of Views 2.1, OR operations on filters are not supported. This is, however, a planned feature that will make it's way into Views 2 at some point.
In the mean time, there are several options. Note that none of them can be considered forward compatible :
Option 1 : Views Or Filter
The Views Or filter lets you do this without any programing, by inserting extra filters in your views that delimit alternatives.
While already used in some production sites, this filter is still considered experimental as it has not undergone sufficient testing.
Option 2 : Views Modify Query filter
If you are a programmer and want to modify the query yourself directly without having to implement a module to do it, you can use the Views Modify Query filter which allows you to add extra code in the view building process.
Hint : In the filter, start by output $this or $this->query and then display the result using the Views
Modify Query field. Study the structures before writing code to implement your changes.
Option 3 : Implement your own code/filter
If you can't get the Views UI to do what you want, you can always fall back to hook_views_query_alter, or implement your own filter module, and modify the logic the way you like.
Hint: Just print out the query using print_() in your custom module inside hook_views_query_alter and then modify the query (which is passed by reference) to what you want.