Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-12T14:21:23.217Z
Answers.Text: Thank you, I tried it. However, the count is still 0 although the e-mail address has already been taken.
Answers.UserDisplayName: Kota.M
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-12T21:34:30.417Z
Answers.Text: You've verified that `$new_email` is actually set to an email address that exists in the `users` table?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-15T16:10:54.817Z
Answers.Text: I think so, `$new_email` is the input of e-mail field in the form.
Answers.UserDisplayName: Kota.M
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-11T23:24:34.037Z
Answers.LastActivityDate: 2019-07-11T23:24:34.037Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-11T15:45:51.957Z
Comments.Text: Try adding `->all()` after `email($new_email)` as per [the example](https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#email)
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-11T15:49:14.127Z
Comments.Text: I tried, but the result is same.
Comments.UserDisplayName: Kota.M
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-12T09:39:20.190Z
Comments.Text: Not related to the question, but you can use ".count()" instead of using ".all()" and count() the result. This saves lots of query time.
Comments.UserDisplayName: Parry Huang
Tags: <plugin-development><craft3><php><query>
Title: User query in PHP does not work
ThreadText: # 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](https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#parameters) 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.  
  
  ---
  
  