I have used this approach successfully in Drupal 6 to create a taxonomy vocabulary, select a term and then usign the following function been able to read the selection and use it in theming.
taxonomy_node_get_terms_by_vocabulary($node, $vid, $key = 'tid')

/* pull this into template.php when ready - sort taxonomy links by vocabulary 2 */
$termsfamily = taxonomy_node_get_terms_by_vocabulary(140,2);
if ($termsfamily) {
foreach ($termsfamily as $key => $termchild) {
$ltermchild = ($termchild->name);
}
}
?>

However when I write the $termsfamily array or the final value $ltermchild, I get NULL every time
This has worked ofr me so far in Drupal 4x and 5x. Does anyone see my error or know how to get this to work in Drupal 6?

Comments

francort’s picture

I think think that could be happening, because you're not giving a proper node to te function, but a number.
perhaps it would work with:

$termsfamily = taxonomy_node_get_terms_by_vocabulary( node_load( 140 ) ,2 );
//$termsfamily = taxonomy_node_get_terms_by_vocabulary(140,2);
if ($termsfamily) {
foreach ($termsfamily as $key => $termchild) {
$ltermchild = ($termchild->name);
}
}
hoobuba’s picture

I am using this function to filter block visibility display. I believe I am passing the $node correctly but it still does not want do the right think anybody has any suggestion?

Thank you!


// showing on blog and archive main page
if (arg(0) == 'blog' or arg(0) == 'archive' ) {
    return TRUE; 
  } elseif (arg(0) == 'node' and is_numeric(arg(1))) {
    $node = node_load(arg(1));
// showing on blog pages
    if ($node->type == 'blog') { 
     return TRUE;
// showing on taxonomy vocabulary 5 --need help with this ...
    } elseif (is_array(taxonomy_node_get_terms_by_vocabulary( $node ,5 ))) {
       return TRUE;
   }  
} else {
    return FALSE;
}
ericfaucon’s picture

I have that kind of problem too.

I used a computed field to get the taxonomy terms associated with a node, using the following code :
$node_field[0]['value'] = print_r(taxonomy_node_get_terms_by_vocabulary($node, 4, $key = 'tid'));
and it worked well, getting me an array of terms associated with the current node.

But when I load the node from the ID of a Nodereference field, I get an empty Array :

$node_reference = $node->field_reference[0];
$node_field[0]['value'] = print_r(taxonomy_node_get_terms_by_vocabulary(node_load($node_reference["nid"]), 4, $key = 'tid')); 

Whereas the node_load returns me the node I want.

Any idea ?