nortmas
5/12/2014 - 8:23 AM

Get field data

Get field data

// way 1
$field_name = field_get_items("node", $node, "field_name");
$field_name = $field_name ? current($field_name): FALSE;
$field_name = $field_name ? check_markup($field_name['value'], $field_name['format']) : FALSE;

// way 2
$field_name = field_get_items("node", $node, "field_name");
$field_name = field_view_value('node', $node, 'field_name', $field_name[0]);
$field_name = render($field_name);

// way 3
$field_name = field_get_items("node", $node, "field_name");
$field_name = $field_name ? current($field_name): FALSE;
$field_name = $field_name ? $field_name['value'] : FALSE;

// way 5
list($node_image) = field_get_items('node', $node, 'field_image');
$node_image_url = file_create_url($node_image['uri']);
$style_array = array('path' => $node_image['uri'], 'style_name' => 'image_style');
$render_image = theme('image_style', $style_array);


// way 4
$field_items = field_get_items('node', $node, 'field_mytestfield');
$field_info = field_info_field('field_mytestfield');
if (!empty($field_items) && _field_filter_items($field_info, $field_items)) {
  $field_name = $field_items[0]['value'];
}

$info = field_info_field('field_some_field');

// Get a reference to the values
$values = &$info['settings']['allowed_values'];

// Manipulate the values in some way, e.g.
$values['new_value'] = 'New Value';

// Save the field
field_update_field($info);