How to do saved Node and get that node Id

I was trying to create a new node programatically by inserting information in node, I used below snippet.

  Saved Node

  $objNode = new StdClass();
  $objNode->title = utf8_encode($strTitle);
  $objNode->type = 'album_image';
  $objNode->status = 1;
  $objNode->moderate = 0;
  $objNode->promote = 0;
  $objNode->sticky = 0;
  $objNode->revision = 0;
  $objNode->comment = 0;
  $objNode = node_submit($objNode);

  $intTimestamp = time();
  $objNode->uid = $uId;
  $objNode->created = $intTimestamp;
  $objNode->changed = $intTimestamp;
  node_save($objNode);
 

  How to get the nid after node_save() in drupal 6

  Previously node_save() returned the $nid but not anymore... so what do we do? 

  It's simple. You have just saved a variable as your node. in our case we use $objNode 

  intInsertedNodeID = $objNode->nid;

  It is easy to use 

No comments: