Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Different fields have different keys for the actual 'value' of the field. For example a regular text field has:


Whereas if I have a field using the email module, it looks like this:


I'm working on a function that saves a whole bunch of fields, and I want it to be as flexible as possible, it has a loop that looks like this:

foreach($person_details as $k=>$detail) {
    $node->{'field_'.$k}[$node->language][0]['value'] = $detail;

This is no good at the moment since 'value' is hard coded, and I have some fields in there that use 'email' and a few others from various modules.

Is there any way to know in advance what the key should be?

share|improve this question
Many fields have more than one data column (image field for example), have you you thought about how you're going to handle those? – Clive Nov 15 '12 at 9:39
up vote 0 down vote accepted

My solution ended up being this:

$field_structure = field_info_field($field_name);
$keys = array_keys($field_structure['storage']['details']['sql']['FIELD_LOAD_CURRENT']['field_data_'.$field_name]);

This gives an array of all the posible data columns for $field_name, where $field_name is something like 'field_my_field'.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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