1

I am in desperate need of help.

I have a custom entity called Question which has a bundle called data. Within the data bundle, I have a collection field called options with two subfields called correct_option & misc_option.

-Question
 -Data
  -options
   -correct_options
   -misc_options

I am desperately trying to programmatically write data into those 2 option fields but the following code is not working:

$field_collection_item_value = 1596; // Get field collection item value.

$field_collection_item = entity_load('field_collection_item', array($field_collection_item_value)); // Load that field collection item.

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

The 1569 is the ID of an existing question entity.

Whenever the code is executed I get the following error:

Fatal error: Call to a member function save() on array

I would appreciate any help. I'm at a loss and not sure how to get this working.

0

Please use below code for update existing field collection data

//$item_id load item id from your node
//enter_update_field_mechine_name replace with your field name  
  $field_collection_value = field_collection_item_load($item_id);
  $field_collection_value->enter_update_field_mechine_name['und'][0]['value'] = 'update text here';
  $field_collection_value->save();

This code worked for me Thank you

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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