0

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!

Cole Henley
  • 1,741
  • 11
  • 20
  • This question will no doubt put you on the right track: http://craftcms.stackexchange.com/questions/4486/what-is-getcontent-the-contentmodel-and-how-do-i-use-it-to-get-and-set-cust – Luke Pearce 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. – Cole Henley May 18 '16 at 12:44

1 Answers1

3

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

Cole Henley
  • 1,741
  • 11
  • 20