I have a view that displays matching nodes, based on contextual arguments.

I'd like to create an exposed filter that filters by node title, displaying a drop down (select) menu with options for every node in the result set.

I can modify / set the contents of the exposed filter using hook_form_alter, but the views query hasn't executed when this hook is called, so I don't have access to the result set. If I use hook_views_post_execute then I have access to the result set, but the exposed filters form has already been rendered.

I know that I could write an EntityFieldQuery to select the nodes and set them within hook_form_alter, but that isn't very DRY as I would effectively be re-writing (and executing) the same query that Views will be executing anyway.

What's the best practice way to achieve what I'm looking for?

1 Answer 1


Since this has gone unanswered, I decided to get creative and it's very easy with Entity Reference, Views Reference Filter and optional Rules.

  1. Add an entity reference field to the content type that will reference its own node. So node/5's field will reference node/5. This can be done with Rules automatically. Old nodes can be updated with VBO if needed.
  2. In your view, Add > Entity Reference with the exact same filters etc. That should be automatic. Remove unwanted fields. Save the view.
  3. Go back to your regular view, add an exposed filter (only for that pane) for the entity reference field we just created with (reference filter) written beside it.
  4. In the exposed filter's settings, choose the Entity Reference view we just created. If it's just using contextual filters, don't worry about sending arguments.

The logic: The view will process the entity reference view first and provide its results to the first view as an exposed filter. I just tested it and it works perfectly. Takes about five minutes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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