I'm trying to pull all events where the event's year from endDate matches the queried year (yearParam). When I have this, it's pulling in all events before the yearParam:

{% set pastEntries = craft.entries({endDate: '<' ~ yearParam}).section('events').order('endDate desc') %}

However, what I'd really like is to get entries that match the yearParam (so if the yearParam is 2017, then any events from 2017 should be pulled in).

Any and all help is greatly appreciated. Thanks!

  • If I'm following you correctly, wouldn't {endDate: '=' ~ yearParam} or {endDate: yearParam} do what you're looking for?
    – Brad Bell
    May 15 '17 at 20:17
  • That did it, @denesis. Thanks!
    – gjhead
    Jun 28 '19 at 14:06

Filtering entries by year with pagination example:

{% set query = craft.request.getQuery() %}
{% set selectedYear = query.year is defined ? query.year|abs : FALSE %}

{% paginate craft.entries({
   section: 'news',
   postDate: '>=' ~ selectedYear,
   postDate: '<' ~ (selectedYear + 1)
}).limit(12) as pageInfo, newsEntries %}

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.