We are building a simple user import plugin, saving the basic user is easy enough but how does one save data to the custom fields added to users

Basic exmaple:

$user = new UserModel();
$user->status = UserStatus::Active;
$user->firstName = 'Fruit';
$user->lastName = 'Studios';
$user->email = 'email@domain.com';

This all works great but i cant work out how I add the custom fields?? The following will abviously not work because 'postCode' is not part of the User Model:

$user->postCode = 'SO23 9UG';

Where am I going wrong?

  • Have you tried $user->postCode and what happens when you do? – Ben Croker Jun 25 '14 at 16:53
  • Throws an error: Property "Craft\UserModel.postCode" is not defined. – Sam Hibberd Jun 25 '14 at 16:59

Got it, just need to use the getContent() function exactly the same as entries:

    'postCode' => 'SO23 9UG',
| improve this answer | |

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.