2

I try to update content type field MYFIELD with code

$update = db_update('field_data_field_MYFIELD')
    -> fields(array('field_MYFIELD_value' => $result))
    -> condition('entity_id', $nid)
    -> execute();

I see changes in database but they not reflected in node view. Also I applied this code to field_revision_field_MYFIELDtable and got the same result. How can I update MYFIELD programmatically?

  • If your database is updated but the changes are not reflected in the node view, I would suggest first trying to clear all cache. But as sam2de said it is better to use the Drupal API for changes to field data. – n30r3b3l Aug 26 '15 at 17:08
1

Better( and simpler) solution is using with drupal Node load and Node save API

$node=node_load($nid);
$node->field_data_field_MYFIELD['und'][0]['value'];
node_submit($node);
node_save($node);
1

It's better to use Drupa API to do that instead of missing with the database directly. you can use field_attach_update to update your field value

$node = node_load($nid);
$field = field_language('node', $node, 'field_your_field');
$node->field[$field_language][0]['value'] = 'Your New value';
field_attach_update('node', $node);

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.