Skip to content

Instantly share code, notes, and snippets.

@kalabro
Last active October 10, 2015 05:48
Show Gist options
  • Save kalabro/3643917 to your computer and use it in GitHub Desktop.
Save kalabro/3643917 to your computer and use it in GitHub Desktop.
Drupal 7: Update pathauto aliases
<?php
/*
* Use in devel/php or with drush scr.
* Compatible with http://drupal.org/project/redirect module.
*/
// Some query.
$result = db_select('node', 'n')
->fields('n', array('nid'))
->condition('n.type', 'article')
->condition('n.status', 1)
->range(0, 300)
->orderBy('n.nid')
->execute();
foreach ($result as $obj) {
$node = node_load($obj->nid);
$node->path = array('pathauto' => TRUE);
pathauto_node_update_alias($node, 'update');
// Or pathauto_taxonomy_term_update_alias() for terms.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment