Created
November 23, 2009 12:45
-
-
Save investic/241052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implementation of hook_views_query_alter(). | |
*/ | |
function modulename_views_query_alter(&$view, &$query) { | |
if ($view->name == 'viewname') { | |
$type_clause = FALSE; | |
// check to see if we already have a node.type clause | |
foreach ($query->where[0]['clauses'] as $clause) { | |
if (substr(0, 10, $clause) == 'node.type ') { | |
// yes, we do | |
$type_clause = TRUE; | |
} | |
} | |
// if we don't, let's OR our content types together and add a clause | |
if (!$type_clause) { | |
// get types from the view | |
$types = $view->filter['type']->options['value']; | |
// we want an OR query | |
$query->where[1]['type'] = 'OR'; | |
// add each type in turn to the clauses and args for this query | |
foreach ($types as $type) { | |
$query->where[1]['clauses'][] = "node.type in ('%s')"; | |
$key = key($query->where[1]['clauses']); | |
next($query->where[1]['clauses']); | |
$query->where[1]['args'][$key] = $type; | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment