Answers.Body: <p>As always, spent hours trying to figure this out and came upon the answer within an hour after posting the question on Stack.</p>
  
  <p>Here's the working code:</p>
  
  <pre><code>    // get entry
      $entry = craft()-&gt;entries-&gt;getEntryById($entryId);
  
      // get ALL users related to entry
      $users = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
      $users-&gt;status = null;
      $users-&gt;relatedTo = [$entry];
      $userIds = $users-&gt;ids();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-20T16:44:14.040Z
Answers.LastActivityDate: 2016-10-20T16:44:14.040Z
Answers.UserDisplayName: Jarrett Barnett
Body: <p>This works (but only obtains the active users):</p>
  
  <pre><code>// get entry
  $entry = craft()-&gt;entries-&gt;getEntryById($entryId);
  
  // get existing users in field
  $entry-&gt;customUserField-&gt;ids();
  </code></pre>
  
  <p>So in attempting to get the non-active users I've switched to using the ElementCriteriaModel but have been unsuccessful:</p>
  
  <pre><code>// get entry
  $entry = craft()-&gt;entries-&gt;getEntryById($entryId);
  
  // get field model
  $field = craft()-&gt;fields-&gt;getFieldByHandle('customUserField');
  
  // get all users for entry+field
  $getUsers = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
  $getUsers-&gt;relatedTo([
      'targetElement' =&gt; $entry,
      'field' =&gt; $field,
      'status' =&gt; null  // user status null
  ]);
  
  $users = $getUsers-&gt;find();
  </code></pre>
  
  <p>I'm certain I'm doing something wrong within my relatedTo parameters. Help!</p>
  
Tags: <plugin-development><users><plugins><entrymodel><usermodel>
Title: Fetching "Pending" Users Related To Entry Within Plugin
ThreadText: # Fetching "Pending" Users Related To Entry Within Plugin
  
  (Asked by: username_0 on 2016-10-20)
  
  This works (but only obtains the active users):
  
  ```
  // get entry
  $entry = craft()->entries->getEntryById($entryId);
  
  // get existing users in field
  $entry->customUserField->ids();
  
  ```
  
  So in attempting to get the non-active users I've switched to using the ElementCriteriaModel but have been unsuccessful:
  
  ```
  // get entry
  $entry = craft()->entries->getEntryById($entryId);
  
  // get field model
  $field = craft()->fields->getFieldByHandle('customUserField');
  
  // get all users for entry+field
  $getUsers = craft()->elements->getCriteria(ElementType::User);
  $getUsers->relatedTo([
      'targetElement' => $entry,
      'field' => $field,
      'status' => null  // user status null
  ]);
  
  $users = $getUsers->find();
  
  ```
  
  I'm certain I'm doing something wrong within my relatedTo parameters. Help!
  
  **Tags:** plugin-development, users, plugins, entrymodel, usermodel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-10-20. Score: 3 | Accepted answer
  
  As always, spent hours trying to figure this out and came upon the answer within an hour after posting the question on Stack.
  
  Here's the working code:
  
  ```
      // get entry
      $entry = craft()->entries->getEntryById($entryId);
  
      // get ALL users related to entry
      $users = craft()->elements->getCriteria(ElementType::User);
      $users->status = null;
      $users->relatedTo = [$entry];
      $userIds = $users->ids();
  
  ```
  
  
  ---
  
  