4

I'm using Link field.

I need to populate link field programmatically. Currently I'm using EMW a lot, so I'm wonder if it possible to set Link field value via EMW.

6

Try this code:

$node = node_load(nid);
$wrapper = entity_metadata_wrapper('node', $node);
$link = array(
  'url' => 'url',
  'title' => 'title',
  'attributes' => array()
);
$wrapper->field_link->set($link);
$wrapper->save();

Don't missing $wrapper->save();

3

If your Link field is multivalue, use this code:

  $node = node_load(nid);
  $wrapper = entity_metadata_wrapper('node', $node);
  $wrapper->field_link[] = array(
     'url' => 'url',
     'title' => 'title',
     'attributes' => array()
   );
  $wrapper->save();

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.