WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Adding a node to an organic group programmatically

Submitted by barnettech on Wed, 05/15/2013 - 10:04

To add a node to an organic group programmatically this code absolutely works as of May 15th 2013.  There are a lot of articles on the web I've read with either incorrect code or outdated code:

 

$entity = node_load($nid); 
$values = array('entity_type' => 'node', 'entity' => $entity, 'field_name' => 'og_group_ref', 'state' => 1);
og_group('node', $row->gid, $values);
node_save($node);