Answers.Body: <p>This should do it:</p>
  
  <pre><code>$entryCriteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $entryCriteria-&gt;authorId = 10;
  $entryModels = $entryCriteria-&gt;find();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-10T08:26:23.547Z
Answers.Text: Thanks, but this does not seem to work :/ Edited my question to show example code...
Answers.UserDisplayName: Matt Wilcox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-09T16:47:27.453Z
Answers.LastActivityDate: 2016-06-09T16:47:27.453Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>Getting entries in plugins is slightly different from within templates and you should read the details on <a href="https://craftcms.com/docs/plugins/working-with-elements" rel="nofollow">Working with Elements</a> in a plugin in the Craft docs.</p>
  
  <p>Taking that as a guide, you need to create an <code>ElementCriteriaModel</code> instance which selects the entries you are interested in:</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $criteria-&gt;authorId = 10;
  </code></pre>
  
  <p>Note that the <code>ElementCriteriaModel</code> won't pull disabled entries by default. If you want to pull both enabled and disabled entries, you can add the <code>status</code> parameter to your query:</p>
  
  <pre><code>$criteria-&gt;status = null;
  </code></pre>
  
  <p>Finally, you need to call <code>find()</code> on the <code>ElementCriteriaModel</code> to fetch the entries matching your criteria:</p>
  
  <pre><code>$entries = $criteria-&gt;find();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-10T10:27:51.413Z
Answers.Text: It was the null status that was throwing me; didn't know about it! Thanks.
Answers.UserDisplayName: Matt Wilcox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-09T16:52:18.007Z
Answers.LastActivityDate: 2016-06-10T10:22:18.743Z
Answers.LastEditDate: 2016-06-10T10:22:18.743Z
Answers.UserDisplayName: Steve Rowling
Body: <p>This seems pretty simple in a template; along the lines of</p>
  
  <pre><code>if( craft.entries.authorId(10) | length ){ ... }
  </code></pre>
  
  <p>But how do I do that from a plugin?</p>
  
  <pre><code>craft-&gt;entries-&gt;authorId(10)
  </code></pre>
  
  <p>doesn't seem to exist and I've been banging my head against the docs not knowing what I'm actually looking for...</p>
  
  <p>[EDIT]</p>
  
  <p>I now have the following code:</p>
  
  <pre><code>$entryCriteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $entryCriteria-&gt;authorId = $existingUser-&gt;id;
  $existingPages = $entryCriteria-&gt;find();
  
  if ($existingPages) {
      AutoUserEntryPlugin::log('User already exists and has a page belonging to them; aborting.', LogLevel::Info);
      throw new Exception(Craft::t("You already have an account and a page created for you. Aborting. You have not been charged."));
  } else {
      AutoUserEntryPlugin::log('User with ID ' . $existingUser-&gt;id . ' does not seem to have a page.', LogLevel::Info);
  }
  </code></pre>
  
  <p>But with a user I know for a fact has an Entry for which they are the author, it's returning "User with ID 1198 does not seem to have a page".</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-10T09:09:38.247Z
Comments.Text: Both Steve and Brad's answers (essentially the exact same code) should work, so there must be something amiss. What's the status of the entry – is it disabled or enabled?
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-10T09:12:08.430Z
Comments.Text: Also, double check if the user with an ID `1198` has in fact authored any entries – easily done by checking for the integer `1198` in the `authorId` column in the `craft_entries` database table.
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-10T10:15:37.797Z
Comments.Text: The entry is disabled!
  
  OK, so I need to add a new criteria to say ignore the status... trying to figure that out now, thanks!
Comments.UserDisplayName: Matt Wilcox
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-10T10:18:28.227Z
Comments.Text: If the entry is disabled, that's your issue. Be advised that the `$entryCriteria->find` won't pull disabled entries by default, but you can add `$entryCriteria->status = null;` to the query to also include disabled entries.
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-10T10:20:07.810Z
Comments.Text: That's the answer, and that's why this code wasn't working yesterday when I tried! Thanks!
Comments.UserDisplayName: Matt Wilcox
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-10T10:20:52.957Z
Comments.Text: Awesome. I'll edit Steve's answer to include that detail.
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Tags: <plugin-development>
Title: How to check if a user has any entries they're an author of... in a plugin?
ThreadText: # How to check if a user has any entries they're an author of... in a plugin?
  
  (Asked by: username_0 on 2016-06-09)
  
  This seems pretty simple in a template; along the lines of
  
  ```
  if( craft.entries.authorId(10) | length ){ ... }
  
  ```
  
  But how do I do that from a plugin?
  
  ```
  craft->entries->authorId(10)
  
  ```
  
  doesn't seem to exist and I've been banging my head against the docs not knowing what I'm actually looking for...
  
  [EDIT]
  
  I now have the following code:
  
  ```
  $entryCriteria = craft()->elements->getCriteria(ElementType::Entry);
  $entryCriteria->authorId = $existingUser->id;
  $existingPages = $entryCriteria->find();
  
  if ($existingPages) {
      AutoUserEntryPlugin::log('User already exists and has a page belonging to them; aborting.', LogLevel::Info);
      throw new Exception(Craft::t("You already have an account and a page created for you. Aborting. You have not been charged."));
  } else {
      AutoUserEntryPlugin::log('User with ID ' . $existingUser->id . ' does not seem to have a page.', LogLevel::Info);
  }
  
  ```
  
  But with a user I know for a fact has an Entry for which they are the author, it's returning "User with ID 1198 does not seem to have a page".
  
  **Tags:** plugin-development
  
  > **Comments:**
  > **username_1**: Both username_3 and username_2's answers (essentially the exact same code) should work, so there must be something amiss. What's the status of the entry – is it disabled or enabled?  
  > **username_1**: Also, double check if the user with an ID `1198` has in fact authored any entries – easily done by checking for the integer `1198` in the `authorId` column in the `craft_entries` database table.  
  > **username_0**: The entry is disabled!  OK, so I need to add a new criteria to say ignore the status... trying to figure that out now, thanks!  
  > **username_1**: If the entry is disabled, that's your issue. Be advised that the `$entryCriteria->find` won't pull disabled entries by default, but you can add `$entryCriteria->status = null;` to the query to also include disabled entries.  
  > **username_0**: That's the answer, and that's why this code wasn't working yesterday when I tried! Thanks!  
  > **username_1**: Awesome. I'll edit username_3's answer to include that detail.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2016-06-09. Score: 4 | Accepted answer
  
  Getting entries in plugins is slightly different from within templates and you should read the details on [Working with Elements](https://craftcms.com/docs/plugins/working-with-elements) in a plugin in the Craft docs.
  
  Taking that as a guide, you need to create an `ElementCriteriaModel` instance which selects the entries you are interested in:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Entry);
  $criteria->authorId = 10;
  
  ```
  
  Note that the `ElementCriteriaModel` won't pull disabled entries by default. If you want to pull both enabled and disabled entries, you can add the `status` parameter to your query:
  
  ```
  $criteria->status = null;
  
  ```
  
  Finally, you need to call `find()` on the `ElementCriteriaModel` to fetch the entries matching your criteria:
  
  ```
  $entries = $criteria->find();
  
  ```
  
  > **Comments:**
  > **username_0**: It was the null status that was throwing me; didn't know about it! Thanks.  
  
  ---
  
  ### Answer by username_2 on 2016-06-09. Score: 2
  
  This should do it:
  
  ```
  $entryCriteria = craft()->elements->getCriteria(ElementType::Entry);
  $entryCriteria->authorId = 10;
  $entryModels = $entryCriteria->find();
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks, but this does not seem to work :/ Edited my question to show example code...  
  
  ---
  
  