3

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.

4

The UserSessionService::getUser method returns a 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');
| improve this answer | |
  • I tried this and it works but now I have a relation field and that's returns 'null' – Maarten Heideman 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.