Is there any way to pass multiple IDs to a Views exposed filter?

We need to pass an array of IDs to the filter.

Notes:

  • There we can see operator "=" but it not taken 1,2 etc.
  • We have tried regular expressions to, but it also not working.
  • We are not using contextual filters.
  • Do you pass series of continues id like as 1,2,3... (or) 1,2,4,55.. – SenthilKumar Mar 6 '14 at 9:06
  • There we can see operator "="but it not taken 1,2 etc. We have tried regular expression to. but it also not working.Please note we are not using Contextual filters – suramya Mar 6 '14 at 9:21
  • what is your views type? page or block? – Yusef Mohamadi Jun 18 '16 at 10:13

You need to use Context Filter to achieve this ....

You can read values from URL , Multiple values can be separated using + or , operator...

  • Your view path should be /some-path/%
  • Add Contextual Filter should be content id or any other id
  • Select Filter Value, Provide default value and select raw value from URL , Path component 2

enter image description here

  • Select Multiple Value setting in More settings

enter image description here

  • You can call your page with path something like http://example.com/some-path/24+25
  • You can read your multiple values from a text box in a view and on submit simply redirect to url like above.
  • Anil - suramaya post that Please note we are not using Contextual filters – SenthilKumar Mar 6 '14 at 9:43
  • I said "You need to use Context Filter to achieve this" , OP Did not mention why they don't want to use Context Filter.. Question says how to pass multiple id in drupal 7 view filter? And my answer fits for question... – Anil Sagar Mar 6 '14 at 9:46
  • Question says How to pass pass multiple id in drupal7 views exposed filter? May be they checked by exposed filter .. anyway if they will use context filter in future .. – SenthilKumar Mar 6 '14 at 9:52
  • Thank you Sentil and Anil for quick reply. Actually we are not use the contextual filter in the view.We used services views.We have added contextual filter and it not retrieve in query string. Let me know we have done anything wrong. is there any way to get multiple id via exposed filters? – suramya Mar 6 '14 at 12:12
  • It would be helpful to know how to pass contextual filters to services views query string.We have used drupal 7 and services 3 – suramya Mar 6 '14 at 14:13

You can pass it using contextual filter,

Remember to choose multiple selection

enter image description here

if we have url http://example.com/test/20+10+12

If your filter filter values is not much pass it in URL but if you have custom id and they are very items I render you views programmatically and passed your arguments to it

$array = array(1,2,3,4,66,5,54,33,22,111,222,333,);
$view = views_get_view('yourviewname');
$view->set_display("yourdisplayneme");
$view->set_arguments($array);
$view->pre_execute();
$view->execute();
$content = $view->render(); 
print $content;

Here is what I did to add a multiple select exposed filter of nid to a view, just make a example for you here.

  • I would like to create a views listing movies('movie' content type).
  • Movie has a cast field which lists actors('actor' content type).
  • I want to have search movies by actors, which need to support multiple select.

In above example, actors are nodes. So I need a views exposed filter to pass multiple nids to views.

What I used to achieve that, is 'entity reference' module. I created a entity reference field in movie content type called 'cast'. Which is referencing to 'actor' content type. Then in 'cast' field setting, remember to tick 'Render Views filters as select list' as below:

enter image description here

Then you will able to add a nids exposed filter in views!!

In my movies views, add a new filter with Content: Cast (field_cast). Then you will see the select list and multiple options as below:

enter image description here

After adding that filter, you will have a multiple select filter and it should look like this:

enter image description here

NOTE: You may get duplicated result in some case, just enable the views advance 'Use aggregation' setting.

enter image description here

That's it! :)

The last thing I would like to do is make the multi select looks better. What I like to use is a jQuery plugin Sumoselect which you can add if you like.

protected by kiamlaluno Oct 1 '16 at 5:05

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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