How do I pass a view an array of node ids? I can create the view using the ui, but the query I want to run is outside the scope of views. I want to run the db query independently, gather the node ids into an array, and then pass it to the view for display. Howvian I make this happen, if at all?

  • Can you please explain this a little more? You can to create a view that shows a in each row a different node?
    – Adam S
    Commented Jun 27, 2011 at 6:33
  • thanks guys... These are great answers. I get quicker and better answers here than on drupal.org!
    – user1750
    Commented Jun 27, 2011 at 17:09

2 Answers 2


You can add a "Content: Nid" contextual filter to your view, so your view will narrow down the content to the NIDs you provided. Make sure you check the "Allow multiple values" box when configuring the contextual filter. This will allow a url like example.com/myview/12+45+78 which would limit the results to node IDs 12, 45 and 78.


If you want to display these nodes formatted with a view_mode, and not for example in a table, you could also use the API for that: node_view_multiple().

Simply pass the array of nid's with the desired $view_mode to that function and it will return an render array that you can return in a block or page callback or directly render with drupal_render().

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.