<p>To mark this as answered, my solution was to use this code to get the current employee IDs regardless of status.</p>

<pre><code>$employees   = $currentUser-&gt;employees-&gt;status('*')-&gt;ids();
</code></pre>

CC BY-SA 3.0
2017-01-21T11:59:57.633Z
2017-01-21T11:59:57.633Z
billythekid
<p>I have this code to save a new user onto a userfield on another user:</p>

<pre class="lang-php prettyprint-override"><code>    $employees   = $currentUser-&gt;employees-&gt;ids();
    $employees[] = $employee-&gt;id;
    $currentUser-&gt;getContent()-&gt;setAttributes(['employees' =&gt; $employees]);
    if (!craft()-&gt;users-&gt;saveUser($currentUser))
    {
        Craft::dd($currentUser-&gt;getErrors());
    }
</code></pre>

<p>Which works fine, however if there's a pending user in the employees field it's not returned in the ids() array. How do I get <em>all</em> user ids from the employees field, not just active users?</p>

<p><strong>Edit:</strong> got it:</p>

<pre><code>    $employees   = $currentUser-&gt;employees-&gt;status('*')-&gt;ids();
</code></pre>

CC BY-SA 3.0
2017-01-20T20:24:01.023Z
Can you add your solution as an official answer, @billythekid?
Brad Bell
<plugin-development><users><field>
Add a user to a userfield when there's a pending user on there
# Add a user to a userfield when there's a pending user on there

(Asked by: username_0 on 2017-01-20)

I have this code to save a new user onto a userfield on another user:
    $employees   = $currentUser->employees->ids();
    $employees[] = $employee->id;
    $currentUser->getContent()->setAttributes(['employees' => $employees]);
    if (!craft()->users->saveUser($currentUser))
    {
        Craft::dd($currentUser->getErrors());
    }

Which works fine, however if there's a pending user in the employees field it's not returned in the ids() array. How do I get all user ids from the employees field, not just active users?
Edit: got it:
    $employees   = $currentUser->employees->status('*')->ids();

**Tags:** plugin-development, users, field

> **Comments:**
> **username_1**: Can you add your solution as an official answer, @username_0?  

---

## 1 answers

### Answer by username_0 on 2017-01-21. Score: 1 | Accepted answer

To mark this as answered, my solution was to use this code to get the current employee IDs regardless of status.
$employees   = $currentUser->employees->status('*')->ids();


---

