1

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!

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

1 Answer 1

2

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 %}
1
  • This will not work, because the 2nd postDate condition overwrites the first. Try something like that: postDate: ([ 'and', '>= ' ~ selectedYear, '< ' ~ (selectedYear + 1) ]),. Sorry for the bad code formatting.
    – Mateng
    Jun 14 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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