NID in new created node title I don't like second node_save. But I need nid for title.

$node = new stdClass();
$node-&gt;type = 'bill';
node_object_prepare($node);
$node-&gt;uid = $user-&gt;uid;
$node-&gt;field_body['und'][0]['value'] = $bodytxt;
$node = node_submit($node);
node_save($node);

$node-&gt;title = 'Bill # '.$node-&gt;nid;
node_save($node);


Is there more elegant way?
Is there more elegant way?


Not really - the NID doesn't exist until the node has been saved the first time, so there is no way around this if you want to save the node title.

However, you could just add the NID to the title when the node is loaded:

function hook_node_load(&amp;$nodes, $types)
{
  foreach($nodes as $node)
  {
    if($node-&gt;type == 'my_type')
    {
      $nodes[$node-&gt;nid]-&gt;title = '#Bill ' . $node-&gt;nid;
    }
  }
}