I have a User entries field called 'company'. I'm writing a bespoke plugin to manage users in the front-end and was wondering how I can access the content of this field in my plugin via the user model?

Any thoughts as struggling a wee bit here!

  • This question will no doubt put you on the right track: craftcms.stackexchange.com/questions/4486/… May 18 '16 at 12:34
  • Thanks @LukePearce - saw that post and have tried to access via $user rather than $entry but with no success. Not sure if this is because am referencing an Entry field but proving difficult to see how to access contents. May 18 '16 at 12:44

Response via Slack from Brandon Kelly:

Accessing custom field values from PHP is the same as in Twig - once you have the UserModel it's just $user->myCustomFieldHandle or $user->myEntriesField->first(), etc.

Managed to get via following: $user->company->first()->title

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.