Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have this code which gives me the number of terms on a node

 $count = count($node->taxonomy)

Is there a way i can restrict this to VID. i only want to get the count for a specific vocabulary.

Oh yeah the site is in D5

here is a link to the page http://national.thedelimagazine.com/8947/delis-austin-issue-2012-pdf-version-available

share|improve this question

1 Answer

up vote 2 down vote accepted

I don't have a D5 system handy, but this would do it in D6:

$count=0;
foreach ($node->taxonomy as $t) {
  if ($t->vid==VID_IN_QUESTION) {
    $count++;
  }
}

and it "should" be the same in D5, but I've said that a lot about D7 and D6 :) If not,

drupal_set_message('<pre>' . print_r($node->taxonomy,true) . '</pre>');

should give you the object information you need to modify above to count. If that doesn't work,

$foo=taxonomy_node_get_terms_by_vocabulary($nid, $vid);
$count=count($foo);

certainly is a roundabout way of getting them if you already have the node loaded.

share|improve this answer
works perfectly thanks – byTheDrop Mar 7 '12 at 1:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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