Inconsistent "UND" value in node fields I'm manually printing my node fields on its template (node--TYPE.tpl.php). Something like:

&lt;div class="row"&gt;
    &lt;div class="press-year col-md-12"&gt;
        &lt;h2&gt;&lt;?php print $year; ?&gt;&lt;/h2&gt;
    &lt;/div&gt;  
&lt;/div&gt;


And my hook_preprocess_node() looks something like:

function MY_MODULE_preprocess_node(&amp;$vars) {
    switch ($vars['type']) {
        case "my_type":
           if (isset($vars["field_year"]["und"][0])) {
              $vars["year"] = $vars["field_year"]["und"][0]["value"];
          }
        break;
    }
}


The output is fine to all fields; however, when I view the node as administrator, no output is printed. I listed all the variables from the hook to see what was happening with the following code.

function MY_MODULE_preprocess_node(&amp;$vars) {
    var_dump($vars);
    ....
}


I'm getting all fields without the "UND" value, $vars["field_year"][0]["value"] instead of $vars["field_year"]["und"][0]["value"].

Do you have any clue why this happens?
I was having the same problem with D7.  The solution for me was to use field_get_items(...) for reading the node data.

$year_items = field_get_items('node', $variables['node'], 'field_year');
$year = $year_items[0]['value'] + 1;


I found the post on Rendering Drupal 7 fields (the right way) very helpful.  It does seem strange that we shouldn't use the $variables provided to the preprocessor and template to read and modify the template variables.  I must be missing something.