1

I installed the Field ollection module in a Drupal 7 site and I added a multi-field (unlimited) field collection with three items.

I need to programmatically delete the field collection.

I used the following code, which does not work.

$field_collection_delete = $node->field_accommodation['und'][$j]['value']; 
entity_delete_multiple('field_collection_item', array($field_collection_delete));

The value in the field collection item is deleted from the database, but the field collection field I added in the content type is still in the database.

I need to delete that too.

screenshot

What code do I need to use to make it happen?

2 Answers 2

1

You need to unset the field from node first!

unset($node->field_accommodation['und'][$j]);
0
0

You should delete field collections by calling $field_collection->delete(); This handles a few other things for you such as deleting the parent entity.

1
  • Thanks @Ben, I tried the $field_collection->delete(); but its work same like the entity_delete_multiple(). Only deleting the field collection item from the field collection and not the field collection value from the content type
    – user10644
    Jan 2, 2014 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.