1

I am trying to get all entries posted from 2018 and only 2018. All the other methods I've seen are for from a specific date or between two dates. Is there a simple way to get all posts from 2018 without having to specify get all entries between 1 January 2018 and 31 December 2018?

The markup below is where I have got to, but this is getting all entries from 2018 onwards. But when I change the >= parameter to == it appears to break it.

{% set event = craft.entries.section('events').startDate('>=' ~ formYear).one() %}
1
2

This should do what you're looking for:

{% set event = craft.entries({
    section: 'events',
    startDate: 'and, >= ' ~ formYear ~ ', < ' ~ (formYear + 1)
}).one() %}

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.