<p>Try this:</p>

<pre><code>$queryAllUsers_email = User::find()
    -&gt;email($new_email)
    -&gt;anyStatus()
    -&gt;all();
</code></pre>

<p>It's likely the email address you're searching for is for a user that isn't activated yet or suspended, etc.</p>

<p>Using <a href="https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#parameters" rel="nofollow noreferrer">anyStatus</a> will search for the user regardless of their status.</p>

CC BY-SA 4.0
2019-07-12T14:21:23.217Z
Thank you, I tried it. However, the count is still 0 although the e-mail address has already been taken.
Kota.M
CC BY-SA 4.0
2019-07-12T21:34:30.417Z
You've verified that `$new_email` is actually set to an email address that exists in the `users` table?
Brad Bell
CC BY-SA 4.0
2019-07-15T16:10:54.817Z
I think so, `$new_email` is the input of e-mail field in the form.
Kota.M
CC BY-SA 4.0
2019-07-11T23:24:34.037Z
2019-07-11T23:24:34.037Z
Brad Bell
<p>I would like to get user query in my custom PHP plugin.</p>

<p>According to this document, the code would be like this.
<a href="https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#example" rel="nofollow noreferrer">https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#example</a></p>

<pre><code>$queryAllUsers_email = User::find()-&gt;email($new_email);
if (count($queryAllUsers_email) &gt; 0) {
    // ...
}
</code></pre>

<p><code>User</code> means <code>Craft\Elements\User</code> class.</p>

<p>However, the count is 0.</p>

<p>It would be grateful for me if you tell me what is wrong.</p>

CC BY-SA 4.0
2019-07-11T15:45:51.957Z
Try adding `->all()` after `email($new_email)` as per [the example](https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#email)
Oli
CC BY-SA 4.0
2019-07-11T15:49:14.127Z
I tried, but the result is same.
Kota.M
CC BY-SA 4.0
2019-07-12T09:39:20.190Z
Not related to the question, but you can use ".count()" instead of using ".all()" and count() the result. This saves lots of query time.
Parry Huang
<plugin-development><craft3><php><query>
User query in PHP does not work
# User query in PHP does not work

(Asked by: username_0 on 2019-07-11)

I would like to get user query in my custom PHP plugin.
According to this document, the code would be like this.
https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#example
$queryAllUsers_email = User::find()->email($new_email);
if (count($queryAllUsers_email) > 0) {
    // ...
}

User means Craft\Elements\User class.
However, the count is 0.
It would be grateful for me if you tell me what is wrong.

**Tags:** plugin-development, craft3, php, query

> **Comments:**
> **username_1**: Try adding `->all()` after `email($new_email)` as per [the example](https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#email)  
> **username_0**: I tried, but the result is same.  
> **username_2**: Not related to the question, but you can use ".count()" instead of using ".all()" and count() the result. This saves lots of query time.  

---

## 1 answers

### Answer by username_3 on 2019-07-11. Score: 1

Try this:
$queryAllUsers_email = User::find()
    ->email($new_email)
    ->anyStatus()
    ->all();

It's likely the email address you're searching for is for a user that isn't activated yet or suspended, etc.
Using anyStatus will search for the user regardless of their status.

> **Comments:**
> **username_0**: Thank you, I tried it. However, the count is still 0 although the e-mail address has already been taken.  
> **username_3**: You've verified that `$new_email` is actually set to an email address that exists in the `users` table?  
> **username_0**: I think so, `$new_email` is the input of e-mail field in the form.  

---

