2

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.

2 Answers 2

1

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.

0

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!

1
  • 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
    Commented Apr 26, 2012 at 19:06

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.