Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-25T17:02:33.757Z
Answers.LastActivityDate: 2014-06-25T17:02:33.757Z
Answers.UserDisplayName: Sam Hibberd
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-25T16:53:45.700Z
Comments.Text: Have you tried $user->postCode and what happens when you do?
Comments.UserDisplayName: Ben Croker
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-25T16:59:03.160Z
Comments.Text: Throws an error: `Property "Craft\UserModel.postCode" is not defined.`
Comments.UserDisplayName: Sam Hibberd
Tags: <plugin-development><users>
Title: How do you save custom fields along with the user/saveUser action?
ThreadText: # 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',
  ));
  
  ```
  
  
  ---
  
  