<p>Agree it'd be nice if it worked that way... I'm not sure why it doesn't, but replacing it with a regular <code>where</code> clause and <code>not in</code> works ok:</p>

<pre><code>$order = Order::find()
    -&gt;isCompleted(true)
    -&gt;where(['not in', 'email', ['nobody@example.com','no@example.com']])
    -&gt;all();
</code></pre>

CC BY-SA 4.0
2020-04-08T16:00:07.950Z
Oh gosh that was a bit obvious! I'll give it a whirl, thank you.
foamcow
CC BY-SA 4.0
2020-04-08T14:53:20.823Z
2020-04-08T14:53:20.823Z
James Smith
<p>When doing an order query I want to omit results for 2 particular email addresses.</p>

<p>It's easy enough to omit results for one address;</p>

<pre><code>$order = Order::find()
    -&gt;isCompleted(true)
    -&gt;email('not email1@somedomain.com')
    -&gt;all();
</code></pre>

<p>But how do I omit more than one email? If I pass an array using ['not', 'email1@somdomain.com', 'email2@otherdomain.com'] then an error is returned stating that email expects a string.
For example, this doesn't work</p>

<pre><code>$order = Order::find()
        -&gt;isCompleted(true)
        -&gt;email(['not', 'email1@somedomain.com', 'email2@otherdomain.com'])
        -&gt;all();
</code></pre>

<p>Nor does passing in an array of addresses within the array</p>

<pre><code>$order = Order::find()
        -&gt;isCompleted(true)
        -&gt;email(['not', ['email1@somedomain.com', 'email2@otherdomain.com']])
        -&gt;all();
</code></pre>

<p>If I pass in 2 email criteria then only the latter is applied.</p>

<p>There has to be a neat way to do this.</p>

<php><plugin-craftcommerce2><elementquery>
How to exclude multiple email addresses from an order query
# How to exclude multiple email addresses from an order query

(Asked by: username_0 on 2020-04-06)

When doing an order query I want to omit results for 2 particular email addresses.
It's easy enough to omit results for one address;
$order = Order::find()
    ->isCompleted(true)
    ->email('not email1@somedomain.com')
    ->all();

But how do I omit more than one email? If I pass an array using ['not', 'email1@somdomain.com', 'email2@otherdomain.com'] then an error is returned stating that email expects a string.
For example, this doesn't work
$order = Order::find()
        ->isCompleted(true)
        ->email(['not', 'email1@somedomain.com', 'email2@otherdomain.com'])
        ->all();

Nor does passing in an array of addresses within the array
$order = Order::find()
        ->isCompleted(true)
        ->email(['not', ['email1@somedomain.com', 'email2@otherdomain.com']])
        ->all();

If I pass in 2 email criteria then only the latter is applied.
There has to be a neat way to do this.

**Tags:** php, plugin-craftcommerce2, elementquery

---

## 1 answers

### Answer by username_1 on 2020-04-08. Score: 1 | Accepted answer

Agree it'd be nice if it worked that way... I'm not sure why it doesn't, but replacing it with a regular where clause and not in works ok:
$order = Order::find()
    ->isCompleted(true)
    ->where(['not in', 'email', ['nobody@example.com','no@example.com']])
    ->all();

> **Comments:**
> **username_0**: Oh gosh that was a bit obvious! I'll give it a whirl, thank you.  

---

