Drupal 7 views how to modify where clause?
Question
I have a situation whereby i have to add a 0-9 link in the contextual filter of the glossary view
How do i change the where clause part? i need to change
SUBSTRING(node.title, 1, :node_title) = :node_title1
to
SUBSTRING(node.title, 1, 1) =REGEXP ('[0-9]')
if certain value == '0-9' i tried to implement hook_views_query_alter but it is not working
function custom_views_query_alter(&$view, &$query){
$current_view=&$view;
switch($current_view->name){
case 'glossary':
if($query->where[0]['conditions'][0]['value'][':node_title1']=='0-9'){
$query->where[0]['conditions'][0]['field']= "SUBSTRING(node.title, 1, 1) =REGEXP ('[0-9]')";
echo "YES";
dpm($query->where);
} } }
No correct solution
OTHER TIPS
I managed to get it working here's the code
function custom_views_query_alter(&$view, &$query){
$current_view=&$view;
switch($current_view->name){
case 'glossary':
if($query->where){
if($query->where[0]['conditions'][0]['value'][':node_title1']=="0-9"){
$query->where[0]['conditions'][0]['field'] = "SUBSTRING(node.title, 1, 1) REGEXP ('[0-9]')";
dpm($query->where);
}
}
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow