tags:

views:

15

answers:

2

How to get list of terms of a node ( by node id) belongs to a particular vocabulary. Is there any drupal function ?

+2  A: 

taxonomy_node_get_terms function.

http://api.drupal.org/api/function/taxonomy_node_get_terms/6

Or also:

taxonomy_node_get_terms_by_vocabulary

http://api.drupal.org/api/function/taxonomy_node_get_terms_by_vocabulary/6

Kevin
+2  A: 

I know there is api for getting list of vocabularies But i am nto sure, one api exist for gettign list of terms of vocabularies.

However, you can try this function. It will work.

function myutils_get_terms_by_vocabulary($vname, $tname = "") {
    $sql = "select td.*
                    from term_data td
                    inner join vocabulary v on td.vid = v.vid
                    where v.name = '%s'";

    if($tname) {
        $result = db_query($sql . " and td.name = '%s'", $vname, $tname);
        return db_fetch_object($result);
    }   else {
    $result = db_query($sql, $vname);
    }

  $terms = array();
  while ($term = db_fetch_object($result)) {
    $terms[$term->tid] = strtolower($term->name);
  }
  return $terms;
}

Basically i created a 'myutils' module for such common functions and added this function there. so that i can use them in all similar scenarios.

Wind Chimez