I know it might be a silly question to ask, but I have a field say a and b, now how to get the value and set the value for a and b.
Right now my code is like this..
$n = node_load($node->id);
$n->title;
I am getting the node title, I want to know how to get and set the value for a and b please, and if i set the value of a and b will itt be saved using
node_save($n);
??
It depends a bit which version you’re using and on the particular field types you’re using, but something like this:
In both cases the field data will be saved along with the node when you call
node_save().It’s worth noting that the
0index 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. Thevaluekey might need to change depending on the type of data that the field holds (for example a filefield will hold thefid(file id) of the file it holds so adjust accordingly.Also
LANGUAGE_NONEmight need to be replaced by the required language code if you’re using the Drupal 7 version.