function my_module_getcategory() {
  $nodes = node_load_multiple(db_query('SELECT nid FROM {node}')->fetchCol());
  $data = array();

  foreach ($node as $nid) {
    print $nid;
    $data[$nid] = drupal_render(node_view($nid, 'full'));

  $json = drupal_json_encode($data);

The above code give me the following error:

Fatal error: Call to undefined function node_load_multiple() in C:\xampp\htdocs\new_task\sites\all\modules\my_module\my_module.module on line 5

How can I fix this error? I verified the Node module is enabled.

  • and in which hook are you trying to run this code? – kalabro Aug 18 '11 at 7:42
  • simple custom function, – user696734 Aug 18 '11 at 8:31
  • drush en node -y – Daniel Wehner Aug 18 '11 at 8:44
  • 1
    @user696734, and where your custom function is called? :) I want to say that it may be called before modules loaded. – kalabro Aug 18 '11 at 8:56

If you call node_load_multiple() from hook_boot(), then the function is not found because at the time hook_boot() is invoked, only the modules implementing it are loaded. Once Drupal completes the bootstrap, all the enabled modules are loaded, and you can call every function implemented by those modules.

The same is true when you call node_load_multiple() from your own PHP file that doesn't bootstrap Drupal before to call any Drupal functions.

Suppose that you have a example.php file that is invoked as http://example.com/example.php; if the file doesn't contain the following code, then Drupal will not bootstrap, and every Drupal function is not available.

define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

In other cases, you should not get the error you are getting. The only possibility is that the node.module file got corrupted when it was copied, but at that point I would expect something else to not work too; for example, if the content of node.module is corrupted, and node_load_multiple() is read as ode_load_multiple(), then you would get the same error when you are looking at a node page (e.g., http://example.com/node/1).

As side note, hook_boot() has been removed from Drupal 8; if you are using that hook in Drupal 7, you will need to change your code, since it would not work anymore with Drupal 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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