I have a matrix field with one "event" block type that contains several fields. One of those fields is a date field. Is there a way to get just blocks with upcoming dates?

2 Answers 2


Here’s how you would do that:

{% set futureEvents = entry.myMatrixField.myDateField('>= '~now) %}

{% for event in futureEvents %}
    {{ event.description }}
{% endfor %}


This actually hadn’t worked as I expected to, but it does as of Craft 2.3.

  • This method is would less of an performance impact than using a conditional to determine whether or not to display the entry in a for loop. Commented Jun 12, 2014 at 10:33
  • 1
    Should this technique work with any matrix field, I have a matrix block which has a field which holds a section ID but {% set pub = globalPubSettings.pubSettings.pubId(entry.section.id) %} is throwing a method not found for pubId? Commented Aug 21, 2014 at 15:44
  • I have the same problem as Sam Hibberd, this method throws a CException "no method or closure with the name 'myDateField'".
    – Florian
    Commented Sep 5, 2014 at 8:44
  • @BrandonKelly Is there a solution for this, just revisting and hoping I can get {% set var = page.matrixField.showOnHome('1') %} to work. Still throwing the same exception. Commented Nov 5, 2014 at 14:42
  • 6
    @SamHibberd Search wouldn’t work here, no. After talking the problem over with Brad at the end of the day yesterday, I realized there was a way we could get it working before 3.0 without breaking existing element types (or at least making them any more broken then they already are in this case). Spent the day working on this, and am happy to report I’ve just gotten it all working for 2.3. Commented Nov 7, 2014 at 0:54

Would this do it?

{% set blocks = entry.matrixFieldHandle %}
{% for block in blocks if block.yourDateField|date >= now|date %}

{% endfor %}

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.