I'm trying to display and paginate entries by years, that aren't necessarily contiguous.

{% set limitPerPage = 6 %}
{% set eagerFields = [
] %}

{% set pressEntries = craft.entries({
    section: 'pressReleases',
    with:    eagerFields,
}).limit(null) %}

{# I plan on building the query dynamically later, I just want test syntax here #}
{% set dateQuery = 'and, >= 2012-01-01, < 2013-01-01' %}

{% paginate pressEntries.postDate(dateQuery).limit(limitPerPage) as pageInfo, pageEntries %}

This works fine, but I'm wondering how to build upon the dateQuery to return more years with something like:
'and, >= 2012-01-01, < 2013-01-01, >= 2014-01-01, < 2015-01-01'

Is this possible?

1 Answer 1


You may be able to piggyback off of this answer on combining arrays of EntryModels, by providing the template with an array of dateQuery conditions.

For each date condition, you could retrieve the entries as you're doing above, and then combine them with the previous results using the method in that answer. You can then call {% paginate %} using the final combined array, which should contain results matching all of your conditions.

As a side note, this does dump a lot of logic into the template for twig to handle - it may be worth building a small Plugin with a Template Variable that takes in an array of dateQuery instructions, handles this processing for you, and then returns the final combined set to be used in your {% paginate %}.

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.