Search code examples
drupaldrupal-7viewdrupal-viewsentityreference

Drupal 7: How to sort nodes on nearest date of referencing entities?


Here's something I can't wrap my head around, and wonder if it is possible at all:

  • I have a content type Events. All events have a date-field.
  • Each Event also has an entity-reference-field to choose an overarching Series.
  • Now, with Views I want to sort the latter Series based on the event-dates (from Events that reference this Series). As such, the series associated with the first upcoming events (compared to 'today'), should be displayed first.

I tried the module Views field view and it does output the first upcoming event for each Series, but it can't be used as a sorting criteria. Are there any other options to achieve this?

Help is greatly appreciated!


Solution

  • Yes, you should be able to handle this using a relationship. You can find these under the 'Advanced' tab on the right side of the Views UI. You'll want to add a relationship to the Series, then add a the date field to your list of sorts. You'll notice a new dropdown option in the options form for relationship. Select your Series here, and save the sort.