Undefined index: und on search-result.tpl.php for Taxonomy Terms I want to show the node title and related taxonomy terms in a table and modifying the search-result.tpl.php to do this.

What I use to for taxonomy terms is that:

&lt;td class="field-item"&gt;
&lt;?php
    $str = '';
    foreach($result['node']-&gt;field_my_taxonomy_term['und'] as $obj) 
        $str .= l($obj['taxonomy_term']-&gt;name, 'taxonomy/term/' . $obj['tid']) . ',&amp;nbsp;';
    print trim($str, ',&amp;nbsp;');
?&gt;
&lt;/td&gt;



This code works in one of my Drupal website and doesn't work on another one and gives this error:

Notice: include() (.../search-result.tpl.php  line 20) Undefined index: und.
Warning: include() (.../search-result.tpl.php  line 20) Invalid argument supplied for foreach().




How can I show the taxonomy terms related to the node in search-result.tpl.php?
It's either that your field has a set language (not 'und' which stands as 'undefined') or that you have no value for field_my_taxonomy_term.

Either way you should add this control before your foreach (I also rewrite it to fit Drupal best practices) :

&lt;td class="field-item"&gt;
  &lt;?php $str = ''; ?&gt;
  &lt;?php if (isset($result['node']-&gt;field_my_taxonomy_term[LANGUAGE_NONE]) &amp;&amp; $result['node']-&gt;field_my_taxonomy_term[LANGUAGE_NONE]): ?&gt;
    &lt;?php foreach ($result['node']-&gt;field_my_taxonomy_term[LANGUAGE_NONE] as $obj): ?&gt;
      &lt;?php $str .= l($obj['taxonomy_term']-&gt;name, 'taxonomy/term/' . $obj['tid']) . ',&amp;nbsp;'; ?&gt;
    &lt;?php endforeach ?&gt;
    &lt;?php print trim($str, ',&amp;nbsp;'); ?&gt;
  &lt;?php endif ?&gt;
&lt;/td&gt;