entity_metadata_wrapper - how to remove one item from entity reference field I have a entity reference field that holds relations to multiple nodes. I have to remove one item programmatically based on nid. Normally to remove item I've just set it to null like this:

$wrapper-&gt;field_foobar = NULL;


But entity reference is a list, so I have to know delta for element to do something like this:

$wrapper-&gt;field_foobar[$delta] = NULL;


So I have content_id and target_id what should I do to find delta? I know it's possible to do it with simple SQL query, but I gues there should be some way to do that with entity metadata . 

Any sugestions? 

I'm on Drupal 7 of course.
Use unset instead, followed by a save:

unset($wrapper-&gt;field_foobar[$delta]);
$wrapper-&gt;save();


To find the delta, you can iterate over the collection and look for the node id:

foreach($wrapper-&gt;field_foobar as $delta =&gt; $item)  {
  if ($item-&gt;nid-&gt;value() == $my_id) {
    unset($wrapper-&gt;field_foobar[$delta]);
    $wrapper-&gt;save();
    break;
  }
}