Craft CMS Asked on January 17, 2021
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!
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.
Answered by ZealousWeb on January 17, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP