User login

Get a node's taxonomy terms that are in a given vocabulary

well, duh:


(No, I am not making that function name up! This is a function provided by Drupal's core taxonomy module.)

taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid')
modules/taxonomy/taxonomy.module, line 744


Find all terms associated with the given node, within one vocabulary.


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;

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


does sort of the same thing for d6

i put this in my node.tpl.php file.

= taxonomy_node_get_terms($node);
$terms as $term){
$term->vid ==2){

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.