hook_views_query_alter Drupal 6.x (substring)


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2. * Implementation of hook_views_query_alter().
  3. */
  4. function local_views_query_alter(&$view, &$query) {
  5. if ($view->name == 'our_partners' && $view->current_display == 'page_1') {
  6. //alter the query so we actually select the results with the surname begining with the arg
  7. $query->where[0]['clauses'][3] = "SUBSTR(reverse(node.title), locate(' ', reverse(node.title)) - 1, 1) = '%s'";
  8. }
  9. if($view->name == 'our_people' && $view->current_display == 'page_1') {
  10. //alter the query so we actually select the results with the surname begining with the arg
  11. $query->where[0]['clauses'][2] = "SUBSTR(reverse(node.title), locate(' ', reverse(node.title)) - 1, 1) = '%s'";
  12. }
  13. if($view->name == 'our_people' && $view->current_display == 'attachment_1') {
  14. //alter the query so we actually select the results with the surname begining with the arg
  15. $query->fields['title_truncated']['field'] = "SUBSTRING( reverse( TRIM( node.title ) ) , locate( ' ', reverse( TRIM( node.title ) ) ) -1, 1 )";
  16. }
  17. if($view->name == 'our_partners' && $view->current_display == 'attachment_1') {
  18. //alter the query so we actually select the results with the surname begining with the arg
  19. $query->fields['title_truncated']['field'] = "SUBSTRING( reverse( TRIM( node.title ) ) , locate( ' ', reverse( TRIM( node.title ) ) ) -1, 1 )";
  20. }
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.