Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I a trying to display a simple event listing. I set up a custom date field called eventDate to note when the event happens.

This code delivers me the list of events sorted by eventDate:

 {% for event in craft.entries.find({section: 'events', order: 'eventDate'}) %}
    <a class="eventSummary" href="{{ event.url }}">
        <span class="date">{{ event.eventDate }}</span>
        <span class="eventTitle">{{ event.title }}</span>
    </a>
{% endfor %}

However, I want to omit events whose eventDate falls before the current date/time. If it were an entry date I guess I'd just use "after", but I am not sure how to apply that to a custom date field.

Any help is appreciated.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I think .after would work, but I've used this way:

{% set entries = craft.entries.section('events').limit(null) %}

{% for entry in entries.eventDate('>=' ~ (now.date)).order('eventDate DESC') %}
    {# Show entry #}  
{% endfor %}
share|improve this answer
    
Thanks. This worked. –  jeff_nordstedt Jul 22 at 20:22

Actually you should be able to specify your custom field as part of the chained element criteria:

{% set currentAndFutureEvents = craft.entries.section('events').eventDate('>= ' ~ now).order('eventDate DESC') %}

Source: https://plus.google.com/111247306448293182882/posts/Uu6ZuTH1NBu

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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