Drupal - Why is it sometimes $node->field_name, and sometimes $node->field_name['und']?
The lack of the
LANGUAGE_NONE level data seems to indicate that the field has lost the ability to be translated. I've never encountered such a field.
field_get_items() as already pointed out is the canonical way to safely retrieve field data. Any fields that don't work with field_get_items should be considered broken.
I would hazard a guess that you either
- Have a broken contrib module that re-arranges field data and doesn't know better than to sometimes remove the language level.
- Your field settings have just broken somewhere along the way. Potentially because of a reason similar to above.
Does the problem keep happening on newly created fields?
Can you reproduce on a clean install?
I believe you need a combination of
In your case (I can't test this):
$item = field_get_items('node', $node, 'field_phone'); // unsafe to print $output = field_view_value('node', $node, 'field_phone', $item); print $output;
EDIT: In the above code, line 2 (
$output = ...), I added in
$item because I failed to see that
$item requires a delta. This allows for fields which have multiple values to be iterated over and passed through
field_view_value(). I believe you are skipping the important step of using
If using the above code (including
field_view_value()) doesn't solve this, I would need more information; e.g. seeing your node.tpl.php and possibly a content type export.