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.
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.
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)