2

I have following custom fields for users.

favouriteEntries - 'entry' type field with multiple entries per user
notificationPreference - Lightswitch field

My plugin should email notifications to users who follow that entry when there is an update to a particular entry (Entry::EVENT_AFTER_SAVE).

use craft\elements\User;

$users = User::find()->all();

With the above code, I can get all user data including notificationPreference but favouriteEntries. favouriteEntries field returns null even if it has entries for all users.

What's the correct way to get all user data including favouriteEntries field?

  • 1
    favouriteEntries should never ever return null in no case since it will always contain an object of type ElementQuery. Could you eventually show your entire code? – Robin Schambach Sep 17 '18 at 10:22
3

You should be able to access the custom fields on element\user object.

Craft::$app->getUser()->getIdentity()->getFieldValue('customfieldname');
|improve this answer|||||
1

If someone lands here searching for a Twig answer like me.

{{ currentUser.customFieldHandle }}
|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.