Answers.Body: <p>You can do this using the Lowblocks plugin:</p>
  
  <p><a href="https://github.com/low/lowblocks" rel="nofollow noreferrer">https://github.com/low/lowblocks</a></p>
  
  <p>Im using it for exactly the same thing.</p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/39/search-matrix-for-blocks-with-upcoming-dates/41#comment5242_41">Brandon Kelly has said</a> he's working on an enhancement in 2.3 to allow filtering Matrix fields by date.</p>
  
  <p>In the meantime I used this temporary workaround...</p>
  
  <pre><code>{% set allDates = craft.lowblocks.blocks.fieldId(136).type('mbDate').order('mfDate').limit(null) %}
  
  {% set upcomingIds = [] %}
  
  {% for item in allDates if item.mfDate &gt; now %}
  
      {% set upcomingIds = upcomingIds | merge([item.id]) %}
  
  {% endfor %}
  
  {% set upcomingDates = craft.lowblocks.blocks.id(upcomingIds).fieldId(136).type('mbDate').order('mfDate').limit(30) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T11:08:15.633Z
Answers.Text: The plugin seems to be exactly what I need! I have only one problem using it: I'd like to query only blocks with a future `date` value. I tried using `craft.lowblocks.blocks.fieldId(12).date('>= NOW()')` but I get a _Craft\ElementCriteriaModel and its behaviors do not have a method or closure named "date"_ exception. Ordering block using the date field works however: `craft.lowblocks.blocks.fieldId(12).order('date DESC')`. Can you give me an example how you did it?
Answers.UserDisplayName: michaelhue
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-15T12:30:30.543Z
Answers.Text: Sorry I forgot about that bit. I've edited my answer to include a link to a comment by BK who's said he's working on this issue for 2.3, and also a temporary workaround I used. Hope it helps.
Answers.UserDisplayName: Jamie Pittock
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-17T08:37:52.867Z
Answers.Text: Thanks for the workaround! Looking forward to the updated version of the Lowblocks plugin but for now, this is the best answer to my problem. Thank you Jamie!
Answers.UserDisplayName: michaelhue
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-04T19:03:47.573Z
Answers.Text: Just wanted to note that with version 2.3 of Craft this workaround is no longer necessary.
  
  > It is now possible to set custom field parameters on Matrix block queries.
Answers.UserDisplayName: michaelhue
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-12T17:42:31.267Z
Answers.LastActivityDate: 2014-11-15T12:51:23.533Z
Answers.LastEditDate: 2017-04-13T12:51:00.303Z
Answers.UserDisplayName: Jamie Pittock
Answers.Body: <p>If the native solutions seem a bit involved, or if you want some additional calendar processing power for your events <em>(recurring events, calendar display, etc.)</em>, there's also <strong>Craft Calendars</strong>: <a href="http://michaelrog.com/craft/calendars" rel="nofollow">http://michaelrog.com/craft/calendars</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-23T17:16:36.863Z
Answers.Text: Thanks for the suggestion Michael! Your plugin seems very useful but I think it's a bit overkill for my purposes.
Answers.UserDisplayName: michaelhue
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-16T00:31:57.033Z
Answers.Text: Very interested to test your plugin Michael. Tell me if still possible to test please?
Answers.UserDisplayName: migmaker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-20T16:31:18.563Z
Answers.Text: Sure — support@topshelfcraft.com
Answers.UserDisplayName: Michael Rog
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-18T09:43:56.273Z
Answers.LastActivityDate: 2014-11-18T09:43:56.273Z
Answers.UserDisplayName: Michael Rog
Answers.Body: <p>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. </p>
  
  <p>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'.)</p>
  
  <p>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 '<a href="https://github.com/iainurquhart/craft_introvert" rel="nofollow">introvert</a>' to show reverse related entries.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T11:02:42.657Z
Answers.Text: Thanks for your suggestions! Looping through all events  and replicating the pagination behavior is a last resort for me. Two channels would be nice from a data normalizing view but I'm afraid it will be too much of a hassle for the authors. Introvert looks useful, I will keep it in mind! Thanks again!
Answers.UserDisplayName: michaelhue
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-12T15:40:44.633Z
Answers.LastActivityDate: 2014-11-12T15:40:44.633Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I have a section <code>Events</code> with a matrix field (let's call it <code>dates</code>). The matrix features a single block type with a single <code>date</code> field. One <code>Event</code> can have multiple dates. Think theatre plays with multiple show dates.</p>
  
  <p>Now I'd like to create a list of all events, ordered by the <code>date</code> field. This means that the same entry could show multiple times in the list (once for each <code>date</code> 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.</p>
  
  <p>Ideally there is something like <code>craft.entries</code> but for matrix fields. </p>
  
  <h3>Example</h3>
  
  <p>The following example shows three different <code>Event</code> entries, ordered by their <code>date</code>s. Notice how the same entry can appear multiple times.</p>
  
  <ol>
  <li>14/12/01 @8pm - The Great Gatsby (ID #1)</li>
  <li>14/12/01 @8pm - Moby Dick (ID #2)</li>
  <li>14/12/02 @3pm - Snow White (ID #3)</li>
  <li>14/12/02 @5pm - Snow White (ID #3)</li>
  <li>15/12/05 @7pm - The Great Gatsby (ID #1)</li>
  </ol>
  
  <hr>
  
  <p>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!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-12T13:06:56.793Z
Comments.Text: Thanks @JoshAngell for the spelling corrections. English is not my first language as you might be able to tell. :)
Comments.UserDisplayName: michaelhue
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-12T13:08:08.607Z
Comments.Text: No it is very well written - in fact that was why I edited it :)
Comments.UserDisplayName: Josh Angell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-12T15:56:15.433Z
Comments.Text: @michaelhue To be fair, it's only "theatre" in the U.K. I would have left it as "theater". :)
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-15T12:43:26.330Z
Comments.Text: @BradBell OK WE'RE WEIRD.
Comments.UserDisplayName: Josh Angell
Tags: <matrix>
Title: Query entries by matrix date fields for event calendar
ThreadText: # Query entries by matrix date fields for event calendar
  
  (Asked by: username_0 on 2014-11-12)
  
  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 `date`s. Notice how the same entry can appear multiple times.
  
  1. 14/12/01 @8pm - The Great Gatsby (ID #1)
  2. 14/12/01 @8pm - Moby Dick (ID #2)
  3. 14/12/02 @3pm - Snow White (ID #3)
  4. 14/12/02 @5pm - Snow White (ID #3)
  5. 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!
  
  **Tags:** matrix
  
  > **Comments:**
  > **username_0**: Thanks @username_1 for the spelling corrections. English is not my first language as you might be able to tell. :)  
  > **username_1**: No it is very well written - in fact that was why I edited it :)  
  > **username_2**: @username_0 To be fair, it's only "theatre" in the U.K. I would have left it as "theater". :)  
  > **username_1**: @username_2 OK WE'RE WEIRD.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2014-11-12. Score: 1 | Accepted answer
  
  You can do this using the Lowblocks plugin:
  
  <https://github.com/low/lowblocks>
  
  Im using it for exactly the same thing.
  
  [Brandon Kelly has said](https://craftcms.stackexchange.com/questions/39/search-matrix-for-blocks-with-upcoming-dates/41#comment5242_41) he's working on an enhancement in 2.3 to allow filtering Matrix fields by date.
  
  In the meantime I used this temporary workaround...
  
  ```
  {% set allDates = craft.lowblocks.blocks.fieldId(136).type('mbDate').order('mfDate').limit(null) %}
  
  {% set upcomingIds = [] %}
  
  {% for item in allDates if item.mfDate > now %}
  
      {% set upcomingIds = upcomingIds | merge([item.id]) %}
  
  {% endfor %}
  
  {% set upcomingDates = craft.lowblocks.blocks.id(upcomingIds).fieldId(136).type('mbDate').order('mfDate').limit(30) %}
  
  ```
  
  > **Comments:**
  > **username_0**: The plugin seems to be exactly what I need! I have only one problem using it: I'd like to query only blocks with a future `date` value. I tried using `craft.lowblocks.blocks.fieldId(12).date('>= NOW()')` but I get a _Craft\ElementCriteriaModel and its behaviors do not have a method or closure named "date"_ exception. Ordering block using the date field works however: `craft.lowblocks.blocks.fieldId(12).order('date DESC')`. Can you give me an example how you did it?  
  > **username_3**: Sorry I forgot about that bit. I've edited my answer to include a link to a comment by BK who's said he's working on this issue for 2.3, and also a temporary workaround I used. Hope it helps.  
  > **username_0**: Thanks for the workaround! Looking forward to the updated version of the Lowblocks plugin but for now, this is the best answer to my problem. Thank you username_3!  
  > **username_0**: Just wanted to note that with version 2.3 of Craft this workaround is no longer necessary.  > It is now possible to set custom field parameters on Matrix block queries.  
  
  ---
  
  ### Answer by username_4 on 2014-11-18. Score: 1
  
  If the native solutions seem a bit involved, or if you want some additional calendar processing power for your events *(recurring events, calendar display, etc.)*, there's also **Craft Calendars**: <http://username_4.com/craft/calendars>
  
  > **Comments:**
  > **username_0**: Thanks for the suggestion username_4! Your plugin seems very useful but I think it's a bit overkill for my purposes.  
  > **username_5**: Very interested to test your plugin username_4. Tell me if still possible to test please?  
  > **username_4**: Sure — support@topshelfcraft.com  
  
  ---
  
  ### Answer by username_6 on 2014-11-12. Score: 1
  
  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](https://github.com/iainurquhart/craft_introvert)' to show reverse related entries.
  
  > **Comments:**
  > **username_0**: Thanks for your suggestions! Looping through all events  and replicating the pagination behavior is a last resort for me. Two channels would be nice from a data normalizing view but I'm afraid it will be too much of a hassle for the authors. Introvert looks useful, I will keep it in mind! Thanks again!  
  
  ---
  
  