<p>I suspect you're looking for <a href="https://docs.craftcms.com/v2/templating/elementcriteriamodel.html#setting-the-parameters" rel="nofollow noreferrer">this section</a> on passing parameters to <code>ElementCriteriaModel</code>s, in the docs.</p>

<p>The examples fail to highlight one aspect of the query you're building, but I think you'll find the same strategies hold up for many field values, as well as basic Element properties (like <code>id</code>, <code>title</code>, etc.)</p>

<p>For example…</p>

<pre><code>craft.users({ myFieldA: [1, 2, 3] }).all()
</code></pre>

<p>…will fetch <code>User</code> Elements with the custom <code>myFieldA</code> matching the values <code>1</code>, <code>2</code>, or <code>3</code>. The <code>or</code> is implicit!</p>

CC BY-SA 4.0
2018-12-12T04:41:41.007Z
Hey man, thanks for your reply. However, that's not exactly what I'm looking for. Your answer is doing an 'OR' filter on ONE field, but I'm trying to do an 'OR' on two different fields and also combine with 'AND' filter with other fields.
Wei
CC BY-SA 4.0
2018-12-11T01:26:24.457Z
2018-12-11T01:26:24.457Z
August Miller
<p>Saying I want to convert the following SQL query into ElementCriteriaModel:</p>

<pre><code>SELECT * FROM users WHERE fieldA = 1 AND (fieldB = 1 or fieldC = 1)
</code></pre>

<p>I can't find a way in ElementCriteriaModel to do so.</p>

<pre><code>{% craft.users({
    fieldA: 1,
    fieldB: 1,
    fieldC: 1, // where can we put the 'or' filter?
}) %}
</code></pre>

<p>I can do this using DbCommand, but just curious if there's anyway we can do that via ElementCriteriaModel?</p>

<elementcriteriamodel><craft2>
ElementCriteriaModel combine with 'and' and 'or' filters
# ElementCriteriaModel combine with 'and' and 'or' filters

(Asked by: username_0 on 2018-12-11)

Saying I want to convert the following SQL query into ElementCriteriaModel:
SELECT * FROM users WHERE fieldA = 1 AND (fieldB = 1 or fieldC = 1)

I can't find a way in ElementCriteriaModel to do so.
{% craft.users({
    fieldA: 1,
    fieldB: 1,
    fieldC: 1, // where can we put the 'or' filter?
}) %}

I can do this using DbCommand, but just curious if there's anyway we can do that via ElementCriteriaModel?

**Tags:** elementcriteriamodel, craft2

---

## 1 answers

### Answer by username_1 on 2018-12-11. Score: 1

I suspect you're looking for this section on passing parameters to ElementCriteriaModels, in the docs.
The examples fail to highlight one aspect of the query you're building, but I think you'll find the same strategies hold up for many field values, as well as basic Element properties (like id, title, etc.)
For example…
craft.users({ myFieldA: [1, 2, 3] }).all()

…will fetch User Elements with the custom myFieldA matching the values 1, 2, or 3. The or is implicit!

> **Comments:**
> **username_0**: Hey man, thanks for your reply. However, that's not exactly what I'm looking for. Your answer is doing an 'OR' filter on ONE field, but I'm trying to do an 'OR' on two different fields and also combine with 'AND' filter with other fields.  

---

