Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Created March 21, 2013 13:50
Show Gist options
  • Save amitaibu/5213138 to your computer and use it in GitHub Desktop.
Save amitaibu/5213138 to your computer and use it in GitHub Desktop.
Make Views seach for LIKE
/**
* Implements hook_views_query_alter().
*/
function devel_views_query_alter(&$view, &$query) {
if (empty($query->where[1]['conditions'][1]['field'])) {
return;
}
$sub_query = $query->where[1]['conditions'][1]['field'];
if (!$conditions = &$sub_query->conditions()) {
return;
}
if (!$conditions_2 = &$conditions[1]['field']->conditions()) {
return;
}
$conditions_2[0]['value'] = '%' . $conditions_2[0]['value'] . '%';
$conditions_2[0]['operator'] = 'LIKE';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment