I have the Organic Groups module working in my site, but when I try to use a simple function like og_load() in my module, I get the following error:

Call to undefined function og_load().

What should I do to use these functions?

3 Answers 3


og_load() is defined on the module file, which means it should be available once the module is enabled. Be sure to call the function when Drupal completed its bootstrap, and loaded all the enabled modules. If you call it inside hook_boot(), or hook_exit(), the function could not be available, if Drupal didn't complete its bootstrap.

Sometimes it's enough to increase the weight of the module calling og_load() to avoid the error (if the function is not called in the hooks I previously described). Execute the following code in hook_install(). (Replace mymodule with the short name of your module.)

$weight = db_query("SELECT weight from {system} WHERE name = 'og' AND type = 'module'")->fetchField();
  ->fields(array('weight' => $weight + 1))
  ->condition('type', 'module')
  ->condition('name', 'mymodule')
  • Well, the module is enabled, and working, and I'm trying to call the function in a simple hook_preprocess_node. I don't quite get how the weight would affect the access to the functions, but i'll check it up thanks
    – david ruiz
    Nov 30, 2012 at 12:54

The function is undefined within the scope of your module because your module doesn't know about the Organic Groups module. You have to invoke the Organic Groups module before you can call its functions. (This is the case when using any module's functions.)

Using module_exists() should do the trick. As a bonus, it'll also protect you from unforeseen errors if the Organic Groups module is ever missing or turned off on your site:

if (module_exists('og')) {
  // your og_load() code goes here

If you are looking for drupal 7, the api function no more exist, instead node_load($group_id) can be used.

Check this issue link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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