How to update particular field of entity in drupal 7 using function field_attach_update

7.x field_attach_update($entity_type, $entity)

Save field data for an existing entity.

When calling this function outside an entity save operation be sure to clear caches for the entity:



$entity_type: The type of $entity; e.g. ‘node’ or ‘user’.

$entity: The entity with fields to save.

Below example to update user

 $user = new StdClass(); $user->uid = $uid; $user->mail = $mail; $user->my_custom_field[LANGUAGE_NONE][0]['value'] = $new_value; field_attach_update('user', $user);

Below example to update node:

$node = node_load(1); // where 1 is the nid you want to change
$update_node = new stdClass();
$update_node->nid = $node->nid;
$update_node->vid = $node->vid;
$update_node->type = $node->type;
$update_node->field_FIELD_NAME['und'][0]['value'] = VALUE_YOU_WANT_TO_CHANGE;
field_attach_update(‘node’, $update_node);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Up ↑

%d bloggers like this: