I need a view that will allow me to provide a list of content that *also* references the same node that the node being viewed references.

If you need further clarification:

If node B references node A, I want all other nodes that also reference node A to be listed in the view. A real life example might be Artists and songs. If you are on a song node that references a particular artist, then the view on the song page should display all other songs which references that artist also.

50 dollars available for this view.


sadashiv’s picture

Instead of using node reference you can make use of taxonomy terms if possible.

You create taxonomy term for each artist and tag all songs of that artist.
A song may also have multiple artist and so have multiple tags of taxonomy terms.
Create a simple view based on contents and the content will show the tags to the song in the result of the view.

tklawsuc’s picture

@mitylite did you ever find a solution to this?

FYI although taxonomies are great, they are not always the solution which is why I assume the question was asked as related content based on a reference. In the example above, based on artists and songs, it doesn't make sense to add a taxonomy to a song to tag it with the artist name to be able to see all other songs for an artist. There has to be a clean solution for this using views (3) and entity references.

khanz’s picture

I am working on something similar with entity reference. You can try the following setup (artist and songs) to see if it works..

1) Add 1st relationship in views 3 selecting "Entity Reference: Referenced Entity" (artist)
2) Add 2nd relationship to "Entity Reference: Referencing Entity" (song)
3) In the second relationship change the dropdown to select the 1st relationship to create a back reference.
4) in the contextual filters add "Content: Nid" filter, selecting "Provide default value " and validating it to Artist content types or as needed.
5) Don't forget to select the relationship in the contextual filter to referencing entity (2nd relationship).

Volvo, Video, Velcro. (I came, I saw, I stuck around.)

tklawsuc’s picture

Thanks @khanz.

I stumbled on this earlier but still not getting what I want. What I have are are houses and agents. An agent is an entity reference on a house. So in my view I created:

  1. Entity Reference: Referenced Entity (A bridge to the Content entity that is referenced via field_agents)
  2. Entity Reference: Referencing entity (A bridge to the Content entity that is referencing Content via field_agents)
  3. I added the back reference to the first reference
  4. contextual filter is content nid with default value as content ID from url and set it to the second reference
  5. I also checked the exclude option so that the current node is not displayed in the list

However I am not getting any results. I tried the two different relationships on the fields too. I must be missing something very simple.

UPDATE - I got it to work by not setting any relationship on the fields and not using the exclude checkbox on the context. However I need a way to exclude the current node from the list...when I use exclude then the relationship don't work.


wooody’s picture

You are right Tom,, We just need to exclude the current node from the list.

update: I fix it.. you Just need to add new Contextual filters ,, and Select Content:Nid and Dont select any relation ,,,
Provide default value - Content ID from URL

and from More -- Select Exclude.


Allan Walker’s picture

Thanks wooody for your solution, works a treat.

Just to clarify, this solution requires two Content:Nid contextual filters. The first one should have the "Referencing Entity" relationship selected, while the second one should have no relationship and "Exclude" selected under "More" - as mentioned above.

This way the results are filtered based on the node in question, and THEN the node is removed from the list; trying to do it in one go takes the current node out of the equation entirely.

murraybiscuit’s picture

Thanks Tom (and the rest of the posters in this thread).
I was having the same issue with Authors referenced by Books, and this thread sorted me out.
I didn't notice that a reference could be referenced itself. Always good to learn.
+100 Drupal points to everybody involved.

gamesfrager’s picture

I knew I had to do something like that, it was just getting the order properly.
Thanks for your help.

josephlau’s picture

I follows the following 2 videos to create "Related Content":


http://vimeo.com/13362580 (although this video shows how to do it in Drupal 6, I follows the similar procedures and find it perfect)