I try to create pro grammatically node using node_save(Node), but i cant get nid from node i created.

when i try to dump node_save, just return 1

$myresult = node_save($my_new_node);
print_r($myresult);

only return 1, not nid

 

How to get nid after node_save?

Accepted answer

When you do node_save($my_new_node); , $my_new_node should be the node object, which will get updated. So then you just need to do print_r($my_new_node->nid); to get the NID.

Comments

When you do node_save($my_new_node); , $my_new_node should be the node object, which will get updated. So then you just need to do print_r($my_new_node->nid); to get the NID.