I am working on a custom drupal module that would change a node's node reference field value dynamically if a user clicks on an AJAX button.
In my callback function I could load the two nodes, A and B, where A has a node reference CCK field named 'foobar'.
How can I set edit and save this field? This is my attempt, but if I refresh the node, the field doesn't get updated.
$A_node = node_load($a_nid);
$B_node = node_load($b_nid);
$A_node->field_foobar[0]['nid'] = $b_nid;
node_save($A_node);
To save CCK fields, you need to call more than one function to save the complete node.
content_presave($node);
node_save($node);
content_insert($node);
Try this you might get all data inserted into database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.