Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have an event, which has a field called 'field_location'. I want to create a view on the event page where all other events are listed with the same location. In this case location is a node reference to a node (with content type 'location').

How can I dynamically filter all my event nodes on 'location value of the current event'? I tried this with contextual filters but here it only checks the field you use, in this case 'field_location', with the content id of the url.

I already tried this but without success.

Using PHP Code in the contextual filter

I get zero results.

share|improve this question

migrated from stackoverflow.com Apr 23 '12 at 13:36

This question came from our site for professional and enthusiast programmers.

Use Page manager and panels and add the view as a content pane. Then, pass the node's field's value as an argument to the pane(s) on the panel and you should be good to go.

share|improve this answer

Try this for you php code instead:

$node = menu_get_object();
return $node->field_location['und'][0]['target_id'];

Does that work?

There's a similar question with a few answers here too: views and contextual filters with entity reference field. There are also comments in that discussion about approaches that avoid poking around the node object and avoiding the ['und'][0] business. Check that out too!

share|improve this answer
Alright tried that. I can't find a working solution. Is there also a way to output the value that you want to return to get an idea what's getting returned in the PHP Code? – Mr.B Apr 26 '12 at 19:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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