robdecker
5/10/2014 - 5:40 PM

Drupal 7: Load a field from a node.

Drupal 7: Load a field from a node.

/**
 * Get a field from a node object.
 * Sometimes the node has a language identifier on the field, sometimes it does
 * not.
 */
function _THEME_NAME_get_field($node, $field_name) {
  if (isset($node->{$field_name}[0])) {
    return $node->{$field_name};
  }
  else {
    return field_get_items('node', $node, $field_name, '');
  }
}