<p>Got it, just need to use the getContent() function exactly the same as entries:</p>

<pre><code>$user-&gt;getContent()-&gt;setAttributes(array(
    'postCode' =&gt; 'SO23 9UG',
));
</code></pre>

CC BY-SA 3.0
2014-06-25T17:02:33.757Z
2014-06-25T17:02:33.757Z
Sam Hibberd
<p>We are building a simple user import plugin, saving the basic user is easy enough but how does one save data to the custom fields added to users</p>

<p>Basic exmaple:</p>

<pre><code>$user = new UserModel();
$user-&gt;status = UserStatus::Active;
$user-&gt;firstName = 'Fruit';
$user-&gt;lastName = 'Studios';
$user-&gt;email = 'email@domain.com';
craft()-&gt;users-&gt;saveUser($user);
</code></pre>

<p>This all works great but i cant work out how I add the custom fields?? The following will abviously not work because 'postCode' is not part of the User Model:</p>

<pre><code>$user-&gt;postCode = 'SO23 9UG';
</code></pre>

<p>Where am I going wrong?</p>

CC BY-SA 3.0
2014-06-25T16:53:45.700Z
Have you tried $user->postCode and what happens when you do?
Ben Croker
CC BY-SA 3.0
2014-06-25T16:59:03.160Z
Throws an error: `Property "Craft\UserModel.postCode" is not defined.`
Sam Hibberd
<plugin-development><users>
How do you save custom fields along with the user/saveUser action?
# How do you save custom fields along with the user/saveUser action?

(Asked by: username_0 on 2014-06-25)

We are building a simple user import plugin, saving the basic user is easy enough but how does one save data to the custom fields added to users
Basic exmaple:
$user = new UserModel();
$user->status = UserStatus::Active;
$user->firstName = 'Fruit';
$user->lastName = 'Studios';
$user->email = 'email@domain.com';
craft()->users->saveUser($user);

This all works great but i cant work out how I add the custom fields?? The following will abviously not work because 'postCode' is not part of the User Model:
$user->postCode = 'SO23 9UG';

Where am I going wrong?

**Tags:** plugin-development, users
> **Comments:**
> **username_1**: Have you tried $user->postCode and what happens when you do?  
> **username_0**: Throws an error: `Property "Craft\UserModel.postCode" is not defined.`  

---

## 1 answers

### Answer by username_0 on 2014-06-25. Score: 4 | Accepted answer

Got it, just need to use the getContent() function exactly the same as entries:
$user->getContent()->setAttributes(array(
    'postCode' => 'SO23 9UG',
));


---

