Drupal – Create New Node With PathAuto

Here is a sample code to create a new page node in Drupal with the “node_save()” and adding the pathauto page.

// Bootstrap Drupal
include_once ‘includes/bootstrap.inc';
include_once ‘./sites/all/modules/path/path.admin.inc';
include_once ‘./sites/all/modules/path/path.module';
include_once ‘./sites/all/modules/node/node.module';

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$node = new stdClass();

$node->type = ‘page';

$node->title = “Page Title”;

node_save($node);

$node = node_load(array(‘title’=>$node->title));

$path = “node/” . $node->nid;

$alias = “some/specific/path”;

path_set_alias($path, $alias);