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.


The UserSessionService::getUser method returns a UserModel.

You can retrieve the custom fields from a UserModel as follows:


Or, following on from your example:

  • I tried this and it works but now I have a relation field and that's returns 'null' Apr 28 '17 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.