<p>For most cases you can find a workaround to combine such conditions by making use of entry IDs.</p>

<p>In this example query for each time range condition separately and use the <code>ids()</code> method to "collect" your entries. All matching IDs are then passed to the <code>id</code> parameter of a final ElementCriteriaModel, that you can also use for Pagination etc.:</p>

<pre><code>{% set dateParamCw32 = 'and, &gt;= 2014-08-04 00:00:00, &lt; 2014-08-10 23:59:59' %}
{% set dateParamCw34 = 'and, &gt;= 2014-08-18 00:00:00, &lt; 2014-08-24 23:59:59' %}

{% set entriesCw32Ids = craft.entries.section('events').startDate(dateParamCw32).ids() %}
{% set entriesCw34Ids = craft.entries.section('events').startDate(dateParamCw34).ids() %}

{% set idParam = [] %}
{% set idParam = idParam|merge(entriesCw32Ids) %}
{% set idParam = idParam|merge(entriesCw34Ids) %}

{% set entries = craft.entries.id(idParam) %}
</code></pre>

CC BY-SA 3.0
2014-11-05T10:11:22.653Z
2017-06-29T10:24:44.983Z
2017-06-29T10:24:44.983Z
carlcs
<p>How would you combine multiple logical expressions on a ElementCriteriaModel parameter?
You could query twice and then merge the two returned arrays of entry models,
but that probably wouldn't allow me to later use the <a href="http://buildwithcraft.com/docs/templating/paginate" rel="nofollow"><code>{% paginate %}</code></a> tag or methods like <a href="http://buildwithcraft.com/docs/templating/entrymodel#getNext" rel="nofollow"><code>getNext()</code></a>.</p>

<p>Here's an example where I'd like to filter events starting in calender week 32 or 34:</p>

<pre><code>{% set dateParamCw32 = 'and, &gt;= 2014-08-04 00:00:00, &lt; 2014-08-10 23:59:59' %}
{% set dateParamCw34 = 'and, &gt;= 2014-08-18 00:00:00, &lt; 2014-08-24 23:59:59' %}

{% set startDateParam = 'date range cw32 OR cw34' %}

{% set entries = craft.entries.section('events').startDate(startDateParam) %}
</code></pre>

CC BY-SA 3.0
2014-11-05T15:04:50.347Z
This is a complicated answer and would need to be answered by Pixel & Tonic. Each condition goes through Craft's condition processor and then through Yii's condition processor before finalizing as a query. There's a lot of moving parts, and they would know those parts.
Bryan Redeagle
<elementcriteriamodel>
Complex logic on a ElementCriteriaModel parameter?
# Complex logic on a ElementCriteriaModel parameter?

(Asked by: username_0 on 2014-08-15)

How would you combine multiple logical expressions on a ElementCriteriaModel parameter?
You could query twice and then merge the two returned arrays of entry models,
but that probably wouldn't allow me to later use the {% paginate %} tag or methods like getNext().
Here's an example where I'd like to filter events starting in calender week 32 or 34:
{% set dateParamCw32 = 'and, >= 2014-08-04 00:00:00, < 2014-08-10 23:59:59' %}
{% set dateParamCw34 = 'and, >= 2014-08-18 00:00:00, < 2014-08-24 23:59:59' %}

{% set startDateParam = 'date range cw32 OR cw34' %}

{% set entries = craft.entries.section('events').startDate(startDateParam) %}

**Tags:** elementcriteriamodel
> **Comments:**
> **username_1**: This is a complicated answer and would need to be answered by Pixel & Tonic. Each condition goes through Craft's condition processor and then through Yii's condition processor before finalizing as a query. There's a lot of moving parts, and they would know those parts.  

---

## 1 answers

### Answer by username_0 on 2014-11-05. Score: 9 | Accepted answer

For most cases you can find a workaround to combine such conditions by making use of entry IDs.
In this example query for each time range condition separately and use the ids() method to "collect" your entries. All matching IDs are then passed to the id parameter of a final ElementCriteriaModel, that you can also use for Pagination etc.:
{% set dateParamCw32 = 'and, >= 2014-08-04 00:00:00, < 2014-08-10 23:59:59' %}
{% set dateParamCw34 = 'and, >= 2014-08-18 00:00:00, < 2014-08-24 23:59:59' %}

{% set entriesCw32Ids = craft.entries.section('events').startDate(dateParamCw32).ids() %}
{% set entriesCw34Ids = craft.entries.section('events').startDate(dateParamCw34).ids() %}

{% set idParam = [] %}
{% set idParam = idParam|merge(entriesCw32Ids) %}
{% set idParam = idParam|merge(entriesCw34Ids) %}

{% set entries = craft.entries.id(idParam) %}


---

