1

I have created fields for users and also entry type. I want to get only users fields. I have retrieved custom fields but that returns all the fields.

$users = \craft\elements\User::find()->id(USERID)->one();
print_r($users->getbehaviors()['customFields']);

I know how to get user custom fields with field Handle. I need only users fields (whole users fields not single) that admin assign in the CP. ( settings/users/fields ).

2

You can do this by going via the element's field layout:

$user = \craft\elements\User::find()->id(1)->one();

$fields = $user->getFieldLayout()->getFields();

This will return you an array of all the fields (fields, not values) attached to your user.

1
  • yes It is working. Thanks man.. – Amit Senjaliya Mar 31 '20 at 10:18

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.