Skip to content

Instantly share code, notes, and snippets.

@BramDriesen
Last active October 28, 2017 10:13
Show Gist options
  • Save BramDriesen/030729ea93fd61cee51203b73805007b to your computer and use it in GitHub Desktop.
Save BramDriesen/030729ea93fd61cee51203b73805007b to your computer and use it in GitHub Desktop.
Save a single field value of an entity/node
<?php
$node = node_load(1); // 1 is node id we want to load
// Change field value
$node->field_product_description[$node->language][0]['value'] = 'This is a very nice and useful product. Buy it now! We want your money!';
// Get the numeric id of your field by passing field name
$info = field_info_field('field_product_description');
$fields = array($info['id']);
// Execute the storage function
field_sql_storage_field_storage_write('node', $node, 'update', $fields);
// Clear field cache
cache_clear_all("field:node:$node->nid", 'cache_field');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment