I'm trying to search using an SQL query, I need to search two different things "title" and "title_alt" using user input, I think I can do this using OR however I need to be able to adjust the query when a filter is populated. it's my first day using Drupal and I'm still getting to grips with SQL.
I know I can use explode
and str replace
but should I add a hook and how do I go about testing for a value in my filter?
you should create a custom module, then implement hook_views_query_alter().
this is a very fast snippet, adjust to your needs
/**
* Implements hook_views_query_alter().
*/
function mymodule_views_query_alter(&$view, &$query) {
if ($view->name == 'view_machine_name') {
if (isset($view->args[0]) && is_numeric(($view->args[0]))) {
$query->add_where(0, 'users.uid', 1, '>');
$query->where[0]['type'] = 'OR';
}
}
}