I need to get the terms a node has. I found out that you can use this:

$result = field_view_field('node', $node, 'field_tags', array('default'));

But this prints a rendered list. I need the names, or tids.

How do I separate them?

4 Answers 4


with taxonomy_node_get_terms() function (D6) you can get 'terms from node'. one example:

$terms = taxonomy_node_get_terms($node);// get term from nodes
rsort($terms); //rsort() just sort an array in reverse order
$myterm = $terms[0]->name; //get a value
echo $myterm; //show value
  • -1 Works only for DP6
    – mate64
    Commented Jul 22, 2013 at 8:06

The structure of a taxonomy field in a node is similar to the following one:


The first array index is the identifier of the language associated with the taxonomy, or "und" (the value of the constant LANGUAGE_NONE) if the taxonomy term doesn't have any associated language.


This is how I got it working:

$terms = taxonomy_node_get_terms($node);
$i = 0;

foreach ($terms as $term){ 

    $tid = $term->tid;

    $name = $term->name;

    // show the terms

    print $name.'<br>';


Searching on api.drupal.org I see there is a field_get_items('node', $node, 'field_tags');that you could use.

You can also inspect the $node object and get the values directly from there. To inspect the $node object I recommend you install the devel module and then use the dpm or krumo function like:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.