1

I'm passing along a year as the yearQuery variable. Later in my template, I am doing this:

{% set eventEntries = craft.entries
    .section('events')
    .eventStartDate('>=' ~ yearQuery)
    .eventStartDate('<' ~ (yearQuery + 1))
    .orderBy('eventStartDate asc')
    .limit(12)
%} 

What I want to do is show all entries for a year based on the "eventStartDate" field - and not the date they were posted.

So basically, all Events that were on in 2018, etc.

Is it possible to do this within this query or is there something I am just missing since I have been up way too late? I have a feeling I may be missing something obvious...

1 Answer 1

1

This should work:

{% set year = '2016' %}

{% set eventEntries = craft.entries
    .section('events')
    .where(['>=','field_eventStartDate',year~'-01-01'])
    .andWhere(['<=','field_eventStartDate',year~'-12-31'])
    .orderBy('eventStartDate asc')
    .limit(12)
%} 
1
  • That did it, Udo. Thanks so much!
    – gjhead
    Commented Jun 29, 2019 at 18:56

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.