4.6.x node.php hook_insert($node)
4.7.x node.php hook_insert($node)
5.x node.php hook_insert($node)
6.x node.php hook_insert($node)
7.x node.api.php hook_insert($node)

Respond to node insertion.

This is a hook used by node modules. It is called to allow the module to take action when a new node is being inserted in the database by, for example, inserting information into related tables.


$node: The node being inserted.

Return value


To take action when nodes of any type are inserted (not just nodes of the type(s) defined by this module), use hook_nodeapi() instead.

For a detailed usage example, see node_example.module.

Related topics

2 functions implement hook_insert()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

poll_insert in modules/poll/poll.module
Implementation of hook_insert().
search_query_insert in modules/search/search.module
Return a query with the given module-specific search option inserted in. e.g. 'type:book'.


developer/hooks/node.php, line 295
These hooks are defined by node modules, modules that define a new kind of node.


function hook_insert($node) {
  db_query("INSERT INTO {mytable} (nid, extra)\n    VALUES (%d, '%s')", $node->nid, $node->extra);


Alexander Allen’s picture

The $node->vid and $node->nid variables are generated automatically by the Drupal API.

ryan_courtnage’s picture

If you are wondering, hook_insert() gets called before hook_nodeapi() with op=insert.
see http://api.drupal.org/api/function/node_save/6