Skip to content

Instantly share code, notes, and snippets.

@nigelheap
Created July 18, 2011 06:40
Show Gist options
  • Save nigelheap/1088698 to your computer and use it in GitHub Desktop.
Save nigelheap/1088698 to your computer and use it in GitHub Desktop.
<?php
/**
* Loads a group ID from a node ID
*/
function artroom_ui_og_load_from_nid($nid) {
static $groups;
if (empty($groups)) {
$q = db_select('og');
$q->fields('og', array('gid', 'etid'));
$q->condition('entity_type', 'node', '=');
foreach ($q->execute()->fetchAll() as $row) {
$groups[$row->etid] = $row->gid;
}
}
return og_load($groups[$nid]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment