Query entries by matrix date fields for event calendar I have a section Events with a matrix field (let's call it dates). The matrix features a single block type with a single date field. One Event can have multiple dates. Think theatre plays with multiple show dates.

Now I'd like to create a list of all events, ordered by the date field. This means that the same entry could show multiple times in the list (once for each date in the matrix field). I want to query all future dates in the matrix, fetch related entries, limit the number of items displayed and support pagination.

Ideally there is something like craft.entries but for matrix fields. 

Example

The following example shows three different Event entries, ordered by their dates. Notice how the same entry can appear multiple times.


14/12/01 @8pm - The Great Gatsby (ID #1)
14/12/01 @8pm - Moby Dick (ID #2)
14/12/02 @3pm - Snow White (ID #3)
14/12/02 @5pm - Snow White (ID #3)
15/12/05 @7pm - The Great Gatsby (ID #1)




Can anyone point me in the right direction? I'm not afraid to dive into plugin development (already created a simple "Address" field type with geocoding support) but is there an easier way? Thanks for your time!
I think that in order to do this you are going to need to loop through all events; find eventTimes (within the blocks) that are after the selected date; merge those into an array;  and then return the sorted array. However, by doing so you will loose the ability to easily use pagination. 

Perhaps another solution would be to not use matrix blocks at all and instead create two channels: 1 for 'Shows' and 1 for 'Showtimes' (using your theatre analogy), where 'Showtimes' would be related to 'Shows' using an Entries field-type with limit set to 1. Then finding showtimes would be trivial, and would support pagination, etc. (You could even set the showtimes title to be auto-generated from 'related show title + datetime'.)

And if you wanted to display all the showtimes collected nicely on the Shows entry (for the sake of the client), you can use a nice plugin called 'introvert' to show reverse related entries.