Drupal 6 node_load reset

By shane
Wed, 2011-03-16 00:03
1 comments

Share with Others

I recently had a small issue where my Drupal 6 node object did not have all the current and correct data because the node that was stored in the Drupal node cache was out of date. This is not something I have run into very often (I think only one other time before tonight), however if you run into the same problem then here is the solution:

Rather than just using:

$node = node_load($nid);

Try using:

$node = node_load($nid, NULL, TRUE);

The third parameter clears the Drupal node cache before loading the Drupal 6 node object. The situation I ran into is that I had multiple pieces of information manipulating the node object on a single submit. My changes were not on a node insert/edit page but were on a custom form that provided information that was then loaded in hook_load(). The third parameter can also be useful if you are loading a lot of nodes and want to clear the node cache before you load each node object.

Probably not something you will use everyday, but might be useful if you can't figure out why it seems like using Drupal's node_load() is not giving you the correct information.

Comments

Post new comment