Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal node_save no longer returns $nid, so how do I get it?

I have code like this:

... setup $issue object ...
$node = node_save($issue);

print_r($node);

The node is created successfully, and everything works fine...but nothing it returned from save_node(). Older docs indicate that it returns $nid. Several discussions and tickets indicate that in recent Drupal versions the node object is returned, but I get nothing back (and $node->nid is empty).

So, how do I find out the nid of the newly created node?

like image 200
swelljoe Avatar asked Jun 01 '09 01:06

swelljoe


1 Answers

OK, finally figured this one out (and boy do I feel silly).

node_save now operates on the existing node object (already defined in $issue in my case), and simply adds the nid field (among others) to the existing object. Nothing is returned, but I can access the nid with $issue->nid after node_save has run.

like image 180
swelljoe Avatar answered Nov 09 '22 00:11

swelljoe