5

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.

7

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 %}
10

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

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.