<p>You may be able to piggyback off of <a href="https://craftcms.stackexchange.com/questions/4475/merge-two-arrays-of-elementmodels">this answer</a> on combining arrays of EntryModels, by providing the template with an array of <code>dateQuery</code> conditions.</p>

<p>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 <code>{% paginate %}</code> using the final combined array, which should contain results matching all of your conditions.</p>

<p>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 <a href="https://craftcms.com/docs/plugins/variables" rel="nofollow noreferrer">Template Variable</a> that takes in an array of <code>dateQuery</code> instructions, handles this processing for you, and then returns the final combined set to be used in your <code>{% paginate %}</code>. </p>

CC BY-SA 3.0
2017-01-05T04:08:08.757Z
2017-01-05T04:08:08.757Z
2017-04-13T12:51:00.303Z
Sam LeBlanc
<p>I'm trying to display and paginate entries by years, that aren't necessarily contiguous. </p>

<pre><code>{% set limitPerPage = 6 %}
{% set eagerFields = [
    'title',
    'press_release_name',
    'press_release_date',
    'press_release_body',
] %}

{% 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, &gt;= 2012-01-01, &lt; 2013-01-01' %}

{% paginate pressEntries.postDate(dateQuery).limit(limitPerPage) as pageInfo, pageEntries %}
</code></pre>

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

<p>Is this possible?</p>

<entries><postdate><querystring>
Entries by non-contiguous postDate years
# Entries by non-contiguous postDate years

(Asked by: username_0 on 2017-01-05)

I'm trying to display and paginate entries by years, that aren't necessarily contiguous. 
{% set limitPerPage = 6 %}
{% set eagerFields = [
    'title',
    'press_release_name',
    'press_release_date',
    'press_release_body',
] %}

{% 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?

**Tags:** entries, postdate, querystring

---

## 1 answers

### Answer by username_1 on 2017-01-05. Score: 1

You may be able to piggyback off of [this answer](https://craftcms.stackexchange.com/questions/4475/merge-two-arrays-of-elementmodels) 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](https://craftcms.com/docs/plugins/variables) 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 %}`.


---

