1

I'm able to successfully query a date field for a date range using this syntax:

{% set entries = entries.startsOn(['and', '>= '~firstDay, '< '~ lastDay]) %}

What I would like to do however is query that field for multiple date ranges at once with an or operator.

I can do this with other fields but the date range already using an and operator complicates matters so I can't do the same.

{% set data = data|merge(['or']) %}
{% for item in items %}
     {% set data = data|merge(['*'~item~'*']) %}
{% endfor %}

Any suggestions gratefully received!

1

You can use two queries, each for each range, and then merge them like this:

{% set firstRange = craft.entries({fieldHandle: ['and', '>= '~date1FirstDay, '< '~ date1LastDay]}) %}
{% set secondRange = craft.entries({fieldHandle: ['and', '>= '~date2FirstDay, '< '~ date2LastDay]}) %}

{% set entries = firstRange |merge(secondRange) %}

This is the way to do it. Also you should query for the ids, and then merge those, and then query by id.

I hope this will help.

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.