Search for full word on a views combine filter

Public

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_views_query_alter().
  3. */
  4. function mymodule_views_query_alter(&$view, &$query) {
  5. if ($view->name === 'view_name' && $view->current_display === 'display_id') {
  6. if (!empty($query->where[1]['conditions'][2]['field']) &&
  7. !empty($view->exposed_raw_input['combine'])) {
  8. $combine_filter_arg = $view->exposed_raw_input['combine'];
  9. $query->where[1]['conditions'][2]['field'] = str_replace('LIKE :views_combine', 'REGEXP :views_combine', $query->where[1]['conditions'][2]['field']);
  10. $query->where[1]['conditions'][2]['value'][':views_combine'] = "([[:blank:][:punct:]]|^)" . $combine_filter_arg ."([[:blank:][:punct:]]|$) ";
  11. }
  12. }
  13. }