Hi Drupal developers,

I know that there is a term associated with my node, as I have checked in the DB.

But when I do this (In a flexinode .tpl file or even using template.php) I get an empty Array.

$terms = taxonomy_node_get_terms($node->nid)
print $terms[0];

Well, I do not see a relevant error in the PHP logs, or in the Apache logs, so I do not know how to test if the fuction call has worked.

Please help me to understand how to debug this one?

Alex.

Comments

zhuzhu’s picture

Yeah, I think it can help you:

	unset($terms);
	$terms = taxonomy_node_get_terms($node->nid);
	print_r($terms); //You can see the array before use rsort()
	echo '<br />';
	rsort($terms);
	print $terms[0]->name;
	echo '<br />';
	print_r($terms); //You can see the array after use rsort()

You can use print_r to help you debug arrays.

himansu_ahm’s picture

As Describe below i can't use that function in my site help me for that.

ddegner’s picture

I am having a similar problem, the node has terms but:

unset($terms);
$terms = taxonomy_node_get_terms($node->nid);
print_r ($terms);

returns only:

Array ( )

the code is on a flexinode phpTemplate page.

------------------------------------------------------
Jump through a few hoops, get a free iPod.
http://ipods.freepay.com/?r=8480908

jpatiaga’s picture

If you use Drupal 6 try this:

$terms = taxonomy_node_get_terms($node);

instead of this:

$terms = taxonomy_node_get_terms($node->nid);

xalexas’s picture

To get node TID:

$terms = taxonomy_node_get_terms($node);
rsort($terms);
$myterm = $terms[0]->tid;
echo $myterm;

//to get other taxonomy properties from Array
print_r($terms);