Trying to capture categories field type data in user profile save/update I am trying to capture the data that is selected when a user selects categories within a categories field type (handle: groups) within the Control Panel profile tab.

I was looking thru the Fields, Categories and Content services documentation in the craft docs section and I am still unsure.

I noticed when I did a var_dump of $user:

$user = UserModel::populateModel(UserRecord::model()-&gt;findById($id));


It displays the field 'groups' within the _attributeConfigs, but does not show up in private '_attributes' (Craft\BaseModel)

The other fields do show up, for example, occupation shows up within both the _attributeConfigs (its a string) and shows up in private '_attributes' (Craft\BaseModel) with a value of 'Teacher'.

I am unsure how to get the data the user selected when selecting the categories while updating their profile within the control panel.
Usually, its very easy to pull data from a relational fieldtype (Categories, Entries, Assets etc). E.g. if your Categories field handle is memberGroups, you can simply do this:

$categories = $user-&gt;memberGroups;


However, your Categories field handle is groups, which conflicts with the built-in UserModel attribute groups, used to pull any user groups the user is a member of – this means that calling $user-&gt;groups will give you an array of UserGroupModel instances, ignoring your Categories field.

Also, the $user-&gt;getContent()-&gt;getAttribute('groups'); method doesn't appear to work for relational fields.

The easy answer: I'd suggest you simply change the field handle for your Categories field to something else – for example memberGroups. Don't worry, you won't lose any data if you do. Then you can just do $categories = $user-&gt;memberGroups;.

If you can't or wont change the field handle, here's a workaround:

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
$criteria-&gt;relatedTo = array(
    'sourceElement' =&gt; $user,
    'field' =&gt; 'groups'
);
$categories = $criteria-&gt;find();