I have made this website using Drupal 7 a year ago, where the References module plays a key role.

Say I have two content types movie and actor, and the content type movie has a references field which references actor nodes. Now, how do I have a block which lists other movies which the actors in this movie are referenced?

Something seems to be here: http://drupal.org/node/370227 but that doesn't seem to work for Drupal 7.

Also, as I have more than 1000 nodes in content type movie, I prefer not to move from References field also, my all my urls are like example.com/content-example


1 Answer 1


I am sure you could do all of this in one view using a contextual filter and using that as a relationship to point to the movies in question, but, if you don't mind some php coding, you can do all of this pretty easily yourself and one simpler view.

1.  create a view that has a contextual filter using the actor reference field, eg,
it returns just the movies that contain that actor, and in fields, just nid of the 
movie node should be sufficient.  Make sure that this will reference any actor in the
movie, eg, all of the values of this field, not just the first one.

Then in your block hook, put in something along the lines of:


foreach ($node->NAME_OF_ACTOR_REFERENCE_FIELD as $actor) {
   foreach ($view->result as $result) {

Assuming this is displayed on a page that is displaying a movie of course, what this does is grab the actors referenced in that node and then loops through them, grabbing each movie that has referenced them as well, and then stores that in an array. Since we key this array to the movie's nid, we also create a unique list of movies.

So, now we have a list of movie nids so we can do something like:

foreach ($movies as $nid) {
  $content.='<div class="movie-title-link">' . l($node->title, $node->path) . ' </div>';

and return $content as the content of the block and style it however you want with css.

Caveat: I am just learning D7 and a lot of times D6isms creep into play, and most of the above is just typed in from memory, so there may be subtle things you'll need to adjust (drupal_set_message() and print_r() are your friends) but this hopefully will help out.

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.