Hi,
I have a block view that's bugging me whole day (:
Here's the setup:
I have two content types- Article and Location. Article has entity reference to Location nodes. On Location pages I need to display in a block all articles related to this location and I've done it with contectual filter (ID from URL). My problem is with similar block on Article pages - I want to display all articles that have same Location (entity reference field) as current article.
I've tried adding relationship and using it on contectual filter but it's not working... I tried all I could think of, and looking at Devel I can see the value I want, just can't figure out how to put it in filter (; I've set contectual filter to PHP Code and I'm trying to 'feed' it this value:
$node->field_location[$node->language][0]['target_id']
Anyone knows how to format this to give me the value I need?
Or is there an easier way to display siblings (children nodes that have same parent) on child page? Also would be nice if I could add different class to current node in list of siblings (;
Thanks
Comments
Have you tried adding a
Have you tried adding a contextual filter on the entity reference field
still no luck...
Tried that again, with and without relationship on filters and fields... still not getting any results- location page displays correctlly, but article page that references this location doesn't return anything...
Solved!
I've figured it out!
Solution was to use:
- Contectual filter: Content: Nid with defaults Content ID from URL
- Relationship 1: Entity Reference: Location
- Relationship 2: (Relationship 1) Entity Reference: Referencing entity
- Fields: (Relationship 2) Content: Title
This will lookup current article, load Location entity reference for this article, then load all articles that reference this Location. Hope someone finds this usefull (;
Only thing missing is to figure out how to mark current article with class in the listing... Anyone have some ideas?
This is just what I needed.
This is just what I needed. Thanks for posting the solution!
www.raincreativelab.com
You are a GENIUS
WE HAVE BEEN TRYING TO FIGURE THIS OUT FOR 3 DAYS. This is a life saver.