Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I would like to save a list of values into a entity property.

foreach ($results as $result)
{
   $wrapper->title->set(value);
}

Can an entity property hold an array of values or would I use an entity reference defined as a field for each of my values?

Thanks

share|improve this question
add comment

1 Answer

A field can only hold multiple values if it's been explicitly set to hold more than one value (this is an option when creating the field - see "How many values the field will store" at http://drupal.org/documentation/modules/field-ui ). In that case, the correct syntax using the entity metadata wrapper is to use array operator [] as follow:

$tids = array(....);
$wrapper = entity_metadata_wrapper('node', node_load(1));
foreach ($tids as $tid) {
  $wrapper->field_taxonomy[] = $tid;
}

Please note that in your original example you use the field 'title' - however that is a special drupal field, and it cannot be made to be multi-valued.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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