In this example im setting field empty for term. it has field_rankings named field which is field collection. so here field_ranking is going through a foreach loop because it has fields ids in there so we have to travel it through loop. And than we'll get field value and unset them from ranking array, and save the term so the foreach loop will unset all the field values.
for example fields_ranking is like this before unsetting =
field_rankings = [
und = [
0 => [
value=>123,
ravision=> 1234
]
]
]
foreach ($list as $key => $term) {
$term= taxonomy_term_load($term->tid);
if (!empty($term->field_rankings)) {
foreach ($term->field_rankings[LANGUAGE_NONE] as $key => $value) {
// Build array of field collection values.
$field_collection_item_values[] = $value['value'];
// Unset them.
unset($term->field_rankings[LANGUAGE_NONE][$key]);
}
// Delete field collection items.
entity_delete_multiple('field_collection_item', $field_collection_item_values);
taxonomy_term_save($term);
}
}
Comments
Post a Comment