0

Is it possible to access custom user fields in Joomla 5 via the Joomla user object? The user object gives nice easy access to the standard user fields (as documented here), but it would be very helpful to access the custom fields in a similarly easy way.

If they cannot be accessed via the user object, is there another easy way of accessing them, other than querying the #__fields_values table? Admittedly, the latter isn't particularly difficult, but it would be neater and more efficient to access them via some pre-built functionality.

Thank you!

1 Answer 1

2

Custom fields can be retrieved programmatically using Joomla\Component\Fields\Administrator\Helper\FieldsHelper class:

use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;

$fields = FieldsHelper::getFields('com_users.user', $app->getIdentity());

This returns an array of field objects. If you need the fields to appear with their rendered HTML markup, pass the third argument:

$fields = FieldsHelper::getFields('com_users.user', $app->getIdentity(), true);
1
  • Thank you, @Sharky, that is helpful. I will work with that. Commented Nov 9 at 13:10

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.