Answers:
假设该字段设置为接受多个记录...
$user->field_yourfield_name[LANGUAGE_NONE][0]['tid'] = 27;
$user->field_yourfield_name[LANGUAGE_NONE][1]['tid'] = 28;
// etc
或者,您可以像这样继续追加到数组(不知道下一个可用索引):
$user->field_yourfield_name[LANGUAGE_NONE][]['tid'] = 27;
$user->field_yourfield_name[LANGUAGE_NONE][]['tid'] = 28;
您可以分配一个包含实体元数据包装器的列表值。例如:
<?php
$wrapper = entity_metadata_wrapper('user', $user);
foreach ($wrapper->field_taxonomy_terms->getIterator() as $delta => $term_wrapper) {
// $term_wrapper may now be accessed as a taxonomy term wrapper.
$label = $term_wrapper->name->value();
$tid = $term_wrapper->tid->value();
// you can also set the values
$term_wrapper->name = 'New label';
$term_wrapper->tid = array(123, 1234); // or ...
$term_wrapper->tid->set($tids_to_set);
}
$wrapper->save();
?>