2

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?

7

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') – sobi3ch Mar 26 '15 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) – user1359 Apr 22 '15 at 18:03
  • Assuming you're referring to sobi3ch's comment @user1359, that's a different function (no 's' on the end) – Clive Apr 22 '15 at 18:54

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.