Permalink

really Helpful, its worked straight way , i was trying below code , but not sure where I was mistake as getting error"Integrity constraint violation: 1048 Column 'field_item_target_id' cannot be null"
$nid = 67;
$nod= node_load($nid);
// Create a new field collection
/$field_collection_item = entity_create('field_collection_item', array('field_name' => 'field_order_items'));
$field_collection_item->setHostEntity('node', $nod);

// Load items into field collection
// $field_collection_item->field_item[$nod->language][0]['value'] = "67";
$field_collection_item->field_quantity[$nod->language][0]['value'] = 11;
$field_collection_item->field_type[$nod->language][0]['value'] = "small";

// Save field collection item
$field_collection_item->save();

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.