1

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?

3

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

<?php
$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
  • -1 Works only for DP6
    – mate64
    Jul 22 '13 at 8:06
1

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

screenshot

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.

0
1

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>';

}
1

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:

krumo($node);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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