/ Published in: PHP
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?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) {
// 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')";
$query->where[1]['args'][$key] = $type;
}
}
}
}
?>
Comments
 Subscribe to comments
                    Subscribe to comments
                
                