Updating Individual Node Path via API when using Pathauto in Drupal 6

When saving a node using node_save, the path is not saved when pathauto is enabled for the node type being saved. An exception can be added to the url_alias table using path_set_alias.

  1. $node = new stdClass();
  2. $node->type = 'page';
  3. node_object_prepare($node);
  4. $node->page_title = 'New Page Title';
  5. node_save($node);
  6. $node = node_load(array('title'=>$node-.title));
  7. $path = 'node/' . $node->nid;
  8. $alias = 'some/specific/path';
  9. path_set_alias($path, $alias);

Tags: 

Comments

Perfect. Thanks, Dave!

Or you could just use the following in the initial node_save():
$node->path = 'some/specific/path';

Or if you're trying to get *pathauto* to do its automatic alias:
$node->pathauto_perform_alias = TRUE;

Initially, I tried using $node->path = 'some/specific/path' in the node_save(). However, when pathauto is enabled for that node type, the path value is ignored and the pattern set by pathauto is used instead. The method outlined above is mainly for when pathauto is enabled, but you'd like to use a manually set path instead.

Ah, then you use
$node->pathauto_perform_alias = FALSE;
$node->path = 'some/specific/alias';

Add new comment