Answers.Body: <p>Here's some code that should return categories related to a user:</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
  $criteria-&gt;relatedTo = craft()-&gt;userSession-&gt;getUser();
  
  return craft()-&gt;elements-&gt;findElements($criteria);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-06T15:56:14.830Z
Answers.LastActivityDate: 2016-12-06T15:56:14.830Z
Answers.UserDisplayName: KnutSv
Body: <p>I'm building a service where a few user attributes (category fields) are needed and have to be compared against an entry. </p>
  
  <p>However, when I get the current user and try to load these attributes, they show as <code>NULL</code>. They are filled in at the user's profile, so they shouldn't be <code>NULL</code>.</p>
  
  <p>Below is the code I have used to get try and get the attributes values.</p>
  
  <pre><code>$user = craft()-&gt;userSession-&gt;getUser();
  $user-&gt;getContent()-&gt;getAttributes()
  </code></pre>
  
  <p>Some values are filled out, like the custom field for postal code and phone number. However those category fields are all <code>NULL</code>.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-06T15:49:15.563Z
Comments.Text: Guess the additional parenthesis ")" inside getName is a typo? Anyways, if you use categories I think they're added to a relations table, and not to the user table. So you'd have to query for $categories->relatedTo($user)
Comments.UserDisplayName: KnutSv
Tags: <plugin-development>
Title: Getting custom user attributes in a service, they return NULL
ThreadText: # Getting custom user attributes in a service, they return NULL
  
  (Asked by: username_0 on 2016-12-06)
  
  I'm building a service where a few user attributes (category fields) are needed and have to be compared against an entry.
  
  However, when I get the current user and try to load these attributes, they show as `NULL`. They are filled in at the user's profile, so they shouldn't be `NULL`.
  
  Below is the code I have used to get try and get the attributes values.
  
  ```
  $user = craft()->userSession->getUser();
  $user->getContent()->getAttributes()
  
  ```
  
  Some values are filled out, like the custom field for postal code and phone number. However those category fields are all `NULL`.
  
  **Tags:** plugin-development
  
  > **Comments:**
  > **username_1**: Guess the additional parenthesis ")" inside getName is a typo? Anyways, if you use categories I think they're added to a relations table, and not to the user table. So you'd have to query for $categories->relatedTo($user)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-12-06. Score: 2
  
  Here's some code that should return categories related to a user:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Category);
  $criteria->relatedTo = craft()->userSession->getUser();
  
  return craft()->elements->findElements($criteria);
  
  ```
  
  
  ---
  
  