Skip to content

Instantly share code, notes, and snippets.

@jtwalters
Created November 7, 2014 21:06
Show Gist options
  • Save jtwalters/bad5011c806e614fdc37 to your computer and use it in GitHub Desktop.
Save jtwalters/bad5011c806e614fdc37 to your computer and use it in GitHub Desktop.
<?php
//assuming $node exists
$my_collection = entity_create('field_collection_item', array('field_name' => 'field_my_collection'));
$my_collection->setHostEntity('node', $node);
$my_collection->field_text_data[LANGUAGE_NONE][0]['value'] = "hello";
$my_collection->field_term_ref[LANGUAGE_NONE][0]['tid'] = 123;
$my_collection->field_node_ref[LANGUAGE_NONE][0]['target_id'] = 345;
$my_collection->save();
node_save($node);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment