5 February 2015

The idea would be that you don't take any values directly from node_load result. You can either use entity wrapper(is not a part of this tutorial) or field get and view functions.

Source code viewer
  1. // Those are wrong ways to do this.
  2. $body = $node->body['und'][0]['value'];
  3. $body = $node->body['en'][0]['value'];
  4. $body = $node->body[LANGUAGE_NONE][0]['value'];
  5. $body = $node->body[LANGUAGE_NONE][0]['safe_value'];
  6.  
  7. // THE RIGHT WAY.
  8. // You start the regular way, with loading the entity you want to use.
  9. $node = node_load($nid);
  10.  
  11. // Get renderable array.
  12. $output = field_get_items('node', $node, 'field_name');
  13. // Get raw values.
  14. $output = field_view_field('node', $node, 'field_name');
  15.  
  16. // Raw value of a field, using "value" as an example. If the field is a term reference the value key is "tid" for an example.
  17. $field = field_get_items('node', $node, 'field_name');
  18. $field_first_value = $field[0]['safe_value'];
  19. $field_first_value = $field[0]['tid'];
  20.  
  21. // Render field with default settings.
  22. echo render(field_view_field('node', $node, 'field_name'));
  23.  
  24. // Render field without label.
  25. echo render(field_view_field('node', $node, 'field_name', array('label' => 'hidden')));
  26.  
  27. // IN PROGRESS...
Programming Language: PHP