It depends a bit which version you're using and on the particular field types you're using, but something like this:
// Drupal 6
$n = node_load($node->id);
$n->title = 'A title';
$n->field_my_field_a[0]['value'] = 'A value';
$n->field_my_field_b[0]['value'] = 'B value';
node_save($n);
// Drupal 7
$n = node_load($node->id);
$n->title = 'A title';
$n->field_my_field_a[LANGUAGE_NONE][0]['value'] = 'A value';
$n->field_my_field_b[LANGUAGE_NONE][0]['value'] = 'B value';
node_save($n);
In both cases the field data will be saved along with the node when you call node_save()
.
It's worth noting that the 0
index in both cases refers to the first item in a field. If a field has multiple values you can just keep adding to the array. The value
key might need to change depending on the type of data that the field holds (for example a filefield will hold the fid
(file id) of the file it holds so adjust accordingly.
Also LANGUAGE_NONE
might need to be replaced by the required language code if you're using the Drupal 7 version.