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();

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 ).

1 Answer 1


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.

  • yes It is working. Thanks man.. Commented Mar 31, 2020 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.