Created
November 2, 2012 12:33
-
-
Save rafinskipg/4001074 to your computer and use it in GitHub Desktop.
Views query alter
This file contains 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
function mymodule_views_query_alter(&$view, &$query) { | |
if ($view->name == 'myview' ) { | |
//Filter taxonomy by language | |
global $language; | |
$query->where[] = array( | |
'conditions' => array(array( | |
'field' => 'taxonomy_term_data.language', | |
'value' => array($language->language), | |
'operator' => 'in', | |
)), | |
'args' => array(), | |
'type' => 'AND', | |
); | |
}elseif($view->name =='other_view' && $view->current_display == 'page'){ | |
//Add another table to the relation | |
$query->add_table('field_data_field_evento_ciclo_agenda'); | |
//Get conditions and alter them | |
$condiciones = $query->where['1']['conditions']; | |
$query->where['1']['conditions'][] = array( | |
'field' => 'node.type', | |
'value' => array('event'), | |
'operator' => 'in', | |
); | |
$query->where['1']['conditions'][] = array( | |
'field' => 'field_data_field_evento_ciclo_agenda.field_evento_ciclo_agenda_nid', | |
'value' => array(), | |
'operator' => 'IS NULL', | |
); | |
//Add an extra condition | |
$condiciones[] = array( | |
'field' => 'node.type', | |
'value' => array('season'), | |
'operator' => 'in', | |
); | |
//Update conditions in query | |
$query->where[] = array( | |
'conditions' => $condiciones, | |
'args' => array(), | |
'type' => 'AND', | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment