Home ›
Get a node's taxonomy terms that are in a given vocabularyGet a node's taxonomy terms that are in a given vocabulary
Submitted by Benjamin Melançon on April 15, 2007 - 8:50pm
well, duh:
taxonomy_node_get_terms_by_vocabulary
(No, I am not making that function name up! This is a function provided by Drupal's core taxonomy module.)
Definition
taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid')
modules/taxonomy/taxonomy.module, line 744
Description:
Find all terms associated with the given node, within one vocabulary.
Code:
<?php
function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid') {
$result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.nid = %d ORDER BY weight', 't', 'tid'), $vid, $nid);
$terms = array();
while ($term = db_fetch_object($result)) {
$terms[$term->$key] = $term;
}
return $terms;
}
?>
http://api.drupal.org/api/HEAD/function/taxonomy_node_get_terms_by_vocabulary
Agaric will continue from here to try to use this as an argument in a view...
Searched words:
drupal get all terms from a node in a given vocabulary
drupal get all terms for a node in a vocabulary
get all taxonomy terms for a node in a given vocabulary
Comments
does sort of the same thing for d6
i put this in my node.tpl.php file.
<?php
$terms = taxonomy_node_get_terms($node);
foreach($terms as $term){
if($term->vid ==2){
echo l($term->name,'taxonomy/term/'.$term->tid).' ';
}
}
?>
Post new comment