I have been using Basic Exposed Filter for filtering the zipcode(Number) field.

Now, I want to filter based on the first three number, though the 5 digits number is entered.

How do I achieve this ?

  • You can alter your query by using the hook_views_query_alter. You will find a lot of examples how to use it. You can just alter your condition.
    – Ismini
    Sep 25, 2017 at 10:54
  • In condition, the exposed filter is not showing ? . can you please help me how to do that
    – user78956
    Sep 26, 2017 at 11:32

1 Answer 1


Please check this link

Is has an example how to implement query alter having exposed filters.

function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  // (Example assuming a view with an exposed filter on node title.)
  // If the input for the title filter is a positive integer, filter against
  // node ID instead of node title.
  if ($view->id() == 'my_view' && is_numeric($view->exposed_raw_input['title']) && $view->exposed_raw_input['title'] > 0) {
    // Traverse through the 'where' part of the query.
    foreach ($query->where as &$condition_group) {
      foreach ($condition_group['conditions'] as &$condition) {
        // If this is the part of the query filtering on title, chang the
        // condition to filter on node ID.
        if ($condition['field'] == 'node.title') {
          $condition = array(
            'field' => 'node.nid',
            'value' => $view->exposed_raw_input['title'],
            'operator' => '=',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.