I want to get the list of fields added to user profiles(listed here admin/config/people/accounts/fields). I need machine name and label of each field. How do I get them?
1 Answer
You can use the field_info_instances()
function to get that data:
$fields = field_info_instances('user', 'user');
foreach ($fields as $field) {
$machine_name = $field['field_name'];
$label = $field['label'];
}
-
For anyone that want instance for single field, please use:
field_info_instance('user', 'field_available_date', 'user')
– sobi3chCommented Mar 26, 2015 at 11:29 -
What's the third argument,
user
, for? The manual only shows two arguments: api.drupal.org/api/drupal/modules!field!field.info.inc/function/…field_info_instances($entity_type = NULL, $bundle_name = NULL)
– user1359Commented Apr 22, 2015 at 18:03 -
Assuming you're referring to sobi3ch's comment @user1359, that's a different function (no 's' on the end)– Clive ♦Commented Apr 22, 2015 at 18:54