Is it possible to use a function which uses $node without the expense of node_load


You could just write a query yourself if you don't want to load a whole node object.

It should look something like this:

FROM {term_data} td
INNER JOIN {term_node} tn ON tn.tid = td.tid
WHERE td.vid = 1
AND tn.nid = 1

Then you can just loop through your results and do whatever you need with them.

I don't have easy access to a Drupal database at the moment, so the query might be slightly out..but it should be enough to get you started :)

In this case, I would just look at the source for taxonomy_node_get_terms_by_vocabulary:

function taxonomy_node_get_terms_by_vocabulary($node, $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.vid = %d ORDER BY weight', 't', 'tid'), $vid, $node->vid);
  $terms = array();
  while ($term = db_fetch_object($result)) {
    $terms[$term->$key] = $term;
  return $terms;

The only thing needed is $node->vid. Note that vid in this particular referes to node revision and not vocabulary ID. If you knew the vid, then you could just create your own function:

function mytaxonomy_node_get_terms_by_vocabulary($nodevid, $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.vid = %d ORDER BY weight', 't', 'tid'), $vid, nodevid);
  $terms = array();
  while ($term = db_fetch_object($result)) {
    $terms[$term->$key] = $term;
  return $terms;

The problem is that in most cases you don't know the $node->vid without doing a node_load. Just querying using the nid may or may not be right if you use revisions or start using revisions in the futures. The proper way to do it would be to JOIN the node table into the query so you can use $node->nid as an argument instead of $node->vid.

I asked a similar question a couple days ago. Check the answers here and here.

Similar questions

Does node_load() function prevent multiple loading of the same node?
In some cases, for example page where a lot of block are loading the same current node in one request it could be useful to load node just once for every block. Once I read somewhere this is default functionality for node_load() function. Is it really true, or do I have to workaround that by myslef (store node as global variable or something like t...
who to multiple node load with node_load function in drupal 6?
how is it possible to load a group of nods using Node_load functionality while not utilizing any link of loops ? and send specified "NIDs" list to the nodeload . while the Node_load function doesn't accept an array of NID's . and if you know better function like node_load_multiple in drupal 7 please recomend me .
Can I control which database Drupal uses for certain data?
It is of course possible in a custom modules to use two different databases (and I mean different databases not different RDBMSs!), but is there a way to use two different databases, and then force Drupal to keep certain data in one and other data in the other? For instance, keep nodes (and closely related tables) in one, and all site configuration...
How can I create a programmatic Search API query which uses a date field
I'm trying to create a programmatic Search API query. I've successfully created one which looks for all nodes which are published: However the condition that I want to search for is to find all nodes with a certain date on a date field. The problem is I can't work out how the Search API stores dates. I've tried UNIX time stamps: And the PHP date fo...
How to validate an AJAX form which uses CTools?
I have a form which opens in a modal CTools window. The forms submits perfectly, but when I try to use the my_form_validate() function, it never goes to that function, it always go directly to my_form_submit() function? I have tried to "uncode" the CTools modal windows example provided with the module, but I am not able to decipher it.
How to create a unit test for a class which uses a trait?
Simple as this: I would like to unit test the something() method, but I can't since the StringTranslation trait uses a static container call: What do you suggest?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.