1

How i can use entity_metadata_wrapper for database entry and update data in Drupal 7

I am using below code to save entry in database but not finding logic to update existing entry

    $node = new stdClass();
    $node->type = "event";
    $node->uid = $user_id;          
    $entity_wrapper = entity_metadata_wrapper('node',$node);
    $entity_wrapper->title->set($row->title);
    $entity_wrapper->body->set($row->description);
    $entity_wrapper->status->set(0); 
    $entity_wrapper->promote->set(0);
    $entity_wrapper->comment->set(0);
    $entity_wrapper->field_eventbrite->set($row->eid);          
    $entity_wrapper->field_venue->set($row->name);
    $entity_wrapper->field_eventbrite_city->set($row->city);
    $entity_wrapper->field_privacy->set($row->privacy);
    $entity_wrapper->field_repeats->set($row->repeats);
    $entity_wrapper->field_date_period->set(array(
        'value' => str_replace(' ', 'T',$row->start_date),
        'value2' => str_replace(' ', 'T', $row->end_date),
    ));
    $entity_wrapper->field_eventbrite_url->set(array(
        'url' => $row->url,
    ));
    $entity_wrapper->save();

Please help. Please let me know if require more information is needed.Thanks..

2

Its simple

// $nid - nid of node you want to udate
$node = node_load($nid);
$entity_wrapper = entity_metadata_wrapper('node',$node);
...
$entity_wrapper->field_eventbrite->set($row->eid);          
$entity_wrapper->field_venue->set($row->name);
$entity_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.