Answers.Body: <p>The <a href="https://craftcms.com/classreference/services/UserSessionService#getUser-detail" rel="nofollow noreferrer"><code>UserSessionService::getUser</code> method</a> returns <a href="https://craftcms.com/classreference/models/UserModel" rel="nofollow noreferrer">a <code>UserModel</code></a>.</p>
  
  <p>You can retrieve the custom fields from a <code>UserModel</code> as follows:</p>
  
  <pre><code>$userModel-&gt;getContent()-&gt;getAttribute('fieldName');
  </code></pre>
  
  <p>Or, following on from your example:</p>
  
  <pre><code>craft()-&gt;userSession-&gt;getUser()-&gt;getContent()-&gt;getAttribute('fieldName');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-28T11:15:57.367Z
Answers.Text: I tried this and it works but now I have a relation field and that's returns 'null'
Answers.UserDisplayName: Maarten Heideman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-21T14:03:24.907Z
Answers.LastActivityDate: 2017-03-21T16:07:04.783Z
Answers.LastEditDate: 2017-03-21T16:07:04.783Z
Answers.UserDisplayName: Stephen Lewis
Body: <p>How get the custom user fields in a plugin? I can get the normal fields like firstName like this <code>craft()-&gt;userSession-&gt;user-&gt;firstName</code> but how i can get a custom field i tried <code>craft()-&gt;userSession-&gt;user-&gt;customfieldname</code> but that doesn't work.</p>
  
Tags: <plugin-development>
Title: How get custom user fields in a plugin?
ThreadText: # How get custom user fields in a plugin?
  
  (Asked by: username_0 on 2017-03-21)
  
  How get the custom user fields in a plugin? I can get the normal fields like firstName like this `craft()->userSession->user->firstName` but how i can get a custom field i tried `craft()->userSession->user->customfieldname` but that doesn't work.
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-21. Score: 4 | Accepted answer
  
  The [`UserSessionService::getUser` method](https://craftcms.com/classreference/services/UserSessionService#getUser-detail) returns [a `UserModel`](https://craftcms.com/classreference/models/UserModel).
  
  You can retrieve the custom fields from a `UserModel` as follows:
  
  ```
  $userModel->getContent()->getAttribute('fieldName');
  
  ```
  
  Or, following on from your example:
  
  ```
  craft()->userSession->getUser()->getContent()->getAttribute('fieldName');
  
  ```
  
  > **Comments:**
  > **username_0**: I tried this and it works but now I have a relation field and that's returns 'null'  
  
  ---
  
  