Print list of attached taxonomy terms on search result items First off, let me start by saying I am fairly new to Drupal, I come from a heavy Wordpress / Joomla background. On to my question:

I have looked for hours for a way to print a list of the taxonomy terms attached to a search result item. I need it to be as automated as possible (i.e. I need get the nid &amp; vid from the node automatically if possible). I was able to get the nid using the following:

$nodeID = $variables['result']['node']-&gt;nid;


I do not need any fancy formatting, or hierarchy, I just need a comma separated list of the attached terms for each item on the search results page. If possible, I would also like to limit the depth to 5, but that is not a primary concern.

Here is what I have so far:

// Add List of Terms to Search Result Items
    $vid = 4;
    $terms = array();
      if (isset($node-&gt;taxonomy)) {
        foreach ($node-&gt;taxonomy as $voc) {
          if ($voc-&gt;vid == $vid) {
            $terms[] = $voc;
          }
        }
      } else {
        // check db in case node doesn't have terms
        $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);    
      }
      return $terms;

    $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    // To store the new terms (if necessary...)
    if ($terms) {
        foreach ($terms as $term) {
            // Each term has the properties:
            // $term-&gt;tid
            // $term-&gt;vid
            // $term-&gt;name
            // $term-&gt;description
            // $term-&gt;weight
            // To just print the results use something like: 
            print $term-&gt;name . ',';
        }
    }


Any help you guys can provide would be immensely appreciated!
You almost have it.  How I'd do it is like this.  First, in (I assume you are doing this already) hook_preprocess_search_results:

function YOURMODULE_preprocess_search_results(&amp;$variables) {

  // the vid you are restricting your results to...
  // it is really up to you to define the logic of how
  // to determine this, but you could use a variable...
  $vid=variable_get('YOURMODULE_search_result_vid', 4); 

  $taxonomy=$variables['result']['node']-&gt;taxonomy;

  if ($taxonomy) {

    $terms=array();
    foreach($taxonomy as $t) {
      if ($t-&gt;vid == $vid) {
        $terms[]=$t-&gt;name;
      }
    }

    if ($terms) {
      $variables['terms']=implode(',', $terms);
    }

  }

}


will, assuming no typos and brain fades on my part, produce a $terms variable you can access in search-result.tpl.php.

Now, for step 2, copy the default one out of .../modules/search to your theme.  The default D6 one basically looks like this, with the large intro comments removed:

&lt;dt class="title"&gt;
  &lt;a href="&lt;?php print $url; ?&gt;"&gt;&lt;?php print $title; ?&gt;&lt;/a&gt;
&lt;/dt&gt;
&lt;dd&gt;
  &lt;?php if ($snippet) : ?&gt;
    &lt;p class="search-snippet"&gt;&lt;?php print $snippet; ?&gt;&lt;/p&gt;
  &lt;?php endif; ?&gt;
  &lt;?php if ($info) : ?&gt;
  &lt;p class="search-info"&gt;&lt;?php print $info; ?&gt;&lt;/p&gt;
  &lt;?php endif; ?&gt;
&lt;/dd&gt;


so in there, you can change it up basically like this:

&lt;dt class="title"&gt;
  &lt;a href="&lt;?php print $url; ?&gt;"&gt;&lt;?php print $title; ?&gt;&lt;/a&gt;
&lt;/dt&gt;
&lt;dd&gt;
  &lt;?php if ($snippet) : ?&gt;
    &lt;p class="search-snippet"&gt;&lt;?php print $snippet; ?&gt;&lt;/p&gt;
  &lt;?php endif; ?&gt;
  &lt;?php if ($info) : ?&gt;
  &lt;p class="search-info"&gt;&lt;?php print $info; ?&gt;&lt;/p&gt;
  &lt;?php endif; ?&gt;
  &lt;?php // THE NEW STUFF FOLLOWS... ?&gt;
  &lt;?php if ($terms): ?&gt;
    &lt;p class="search-terms"&gt;&lt;?php print $terms; ?&gt;&lt;/p&gt;
  &lt;?php endif; ?&gt;
  &lt;?php // ...END OF THE NEW STUFF ?&gt;
&lt;/dd&gt;


and with some CSS styling of your new search-terms class, be on your way.