/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Implementation of hook_views_query_alter(). */ function local_views_query_alter(&$view, &$query) { if ($view->name == 'our_partners' && $view->current_display == 'page_1') { //alter the query so we actually select the results with the surname begining with the arg $query->where[0]['clauses'][3] = "SUBSTR(reverse(node.title), locate(' ', reverse(node.title)) - 1, 1) = '%s'"; } if($view->name == 'our_people' && $view->current_display == 'page_1') { //alter the query so we actually select the results with the surname begining with the arg $query->where[0]['clauses'][2] = "SUBSTR(reverse(node.title), locate(' ', reverse(node.title)) - 1, 1) = '%s'"; } if($view->name == 'our_people' && $view->current_display == 'attachment_1') { //alter the query so we actually select the results with the surname begining with the arg $query->fields['title_truncated']['field'] = "SUBSTRING( reverse( TRIM( node.title ) ) , locate( ' ', reverse( TRIM( node.title ) ) ) -1, 1 )"; } if($view->name == 'our_partners' && $view->current_display == 'attachment_1') { //alter the query so we actually select the results with the surname begining with the arg $query->fields['title_truncated']['field'] = "SUBSTRING( reverse( TRIM( node.title ) ) , locate( ' ', reverse( TRIM( node.title ) ) ) -1, 1 )"; } }