2

I am building a site in Drupal 7 that has a list of events. I would like to be able to filter these events by specific date ranges from another content type.

I have successfully been able to set up a view that enables users to filter the list of events by a number of criteria including an arbitrary date range. That much is fine.

However, I would like to allow users to filter the events into date ranges that come from another content type. In this particular case I want the site to show events that occur within the term of office of UK prime ministers. I have set up a content type that has the start and end dates of the term of office of the prime ministers but I can't see how to use this to filter the events.

Ideally I would like a drop down list that allows the user to select a prime minister and this will show a list of events that occur during that prime minister's term of office.

How would you suggest that I do this?

Thank you in advance for your help.

  • I think you will have to write a custom Views 3 filter handler – J. Reynolds Feb 16 '15 at 16:56
1

It's not a dropdown list, but if you don't want to write code, consider the following.

Create a view of all UK PM's in a view. Rewrite the results to output links in the format: events/start_date/end_date.

On your events view (with 'events' path). Add contextual filters catching start_date and end_date.

You could make the first view a jump menu and show it as a block above your events view. This will have the same effect as exposed filters, but will be harder to combine with actual exposed filters.

  • Thanks that's really helpful. I have managed to get this working. In case it helps anyone else I output the links in the format: events/in/YYYY-MM-DD--YYYY-MM-DD rather than using a slash between the start and end dates. – William Mortada Feb 17 '15 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.