1

I have an view with an exposed filer for node IDs, which seems to only accept a single value.

Is there a way to filter nodes giving more than a node ID? I tried 1 and 2, 1,2, and 1 2, but they didn't work.

2 Answers 2

0

I don't think this can be done using only the Views module.

You must create a custom module that implements hook_views_query_alter(). (The code is for Drupal 7.)

function my_module_views_query_alter(&$view, &$query) {
  if ($view->current_display == 'my_current_display' && $view->exposed_raw_input['nid']) {
    $nids = explode(',', $view->exposed_raw_input['nid']);
 
    foreach ($nids as $nid) {
      $query->where[1]['conditions'][] = array(
        'field' => 'node.nid',
        'value' => $nid,
        'operator' => '!=',
      );
    }
  }
}

I found this solution on How to Pass Multiple Values through an Exposed Filter in Drupal Views. Credits go to Peter Schuelke, who wrote that article on October 17, 2012.

0

In views context filter settings is a section where you can enable multiple value splitting, e.g.: 1+2+3 (for OR) or 1,2,3 (for AND)

1
  • Does that work for Drupal 6?
    – apaderno
    Jun 3, 2022 at 11:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.