2 * Implements hook_views_query_alter().
4 function {{ machine_name }}_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
5 // (Example assuming a view with an exposed filter on node title.)
6 // If the input for the title filter is a positive integer, filter against
7 // node ID instead of node title.
8 if ($view->id() == 'my_view' && is_numeric($view->exposed_raw_input['title']) && $view->exposed_raw_input['title'] > 0) {
9 // Traverse through the 'where' part of the query.
10 foreach ($query->where as &$condition_group) {
11 foreach ($condition_group['conditions'] as &$condition) {
12 // If this is the part of the query filtering on title, chang the
13 // condition to filter on node ID.
14 if ($condition['field'] == 'node.title') {
16 'field' => 'node.nid',
17 'value' => $view->exposed_raw_input['title'],