How to create 10 extra nodes when a node of a specific content type is created? I have some business logic in my application where i need to create 10 extra nodes of a content type, when a node of a specific content type is created from Drupal Content Creation page. I know how to programmatically create a node, and I can achieve it via menu hooks, but cant get them done via hook_node_insert() which takes my application into some sort of a loop(maybe because of node_save()). My menu code is an under but I want it to be run from node insert hook.

function nodecreator_menu() {
    $items['admin/create/nodes'] = array(
      'page callback' =&gt; 'nc',
     'access arguments' =&gt; array('access content'),

    );
    return $items;
  }
function nc(){
      $node2 = new stdClass(); // We create a new node object
  $node2-&gt;language = LANGUAGE_NONE;
  $node2-&gt;field_vote_year[$node2-&gt;language][0]['value']="2009-01-01 00:00:00";
  //$node2-&gt;field_select_base_vote[$node2-&gt;language][0]['target_id']=$node-&gt;nid;
  $node2-&gt;field_select_base_vote[$node2-&gt;language][0]['target_id']=8;
  $node2-&gt;type = "vote"; // Or any other content type you want
  $node-&gt;title="Test";
   $node2-&gt;title = $node-&gt;title.$node2-&gt;field_vote_year[$node2-&gt;language][0]['value'];


  node_object_prepare($node2); // Set some default values.
  $node2-&gt;uid = 1; // Or any id you wish
  $node2 = node_submit($node2); // Prepare node for a submit
  node_save($node2);

}
You might experience an infinite loop here since every time you save the node (auto-generated or not), hook_node_insert() gets invoked. To prevent this infinite loop, you can use an extra pseudo-property in your hook_node_insert() to dictate if whether or not nodes should be automatically created.

Below is an example of how your hook_node_insert() might look like:

// If the node is an auto-generated node, don't create additional nodes.
if (!isset($node-&gt;auto_generated)) {
  // Auto-generate 10 nodes.
  for ($i = 0; $i &lt; 10; $i++) {
    // Create a new node object and populate its fields.
    $node2 = new stdClass();
    $node2-&gt;language = LANGUAGE_NONE;
    $node2-&gt;type = "test";
    $node2-&gt;title = "Auto-generated (" . $node-&gt;nid . "-" . $i .")";

    $node2-&gt;created = REQUEST_TIME;
    $node2-&gt;uid = $node-&gt;uid;

    // A flag to let hook_nodeapi() implementations know that this is an automatically
    // generated node.
    $node2-&gt;auto_generated = TRUE;

    // Finally, save the node.
    node_save($node2);

    watchdog('test', "Auto-created node: &lt;pre&gt;@node&lt;/pre&gt;", array(
      '@node' =&gt; print_r($node2, TRUE),
    ));
  }
}