Regenerating Path Aliases Programatically in Drupal 7

It should look something like this:

* Update path aliases for taxonomy terms and nodes.
function gateway_controller_update_7057() {
  module_load_include('inc', 'pathauto');
  module_load_include('inc', 'pathauto.pathauto');

  // Delete the existing node aliases.
    ->condition('source', 'node/%', 'LIKE')

  // Regenerate the node aliases.
  $nids = db_query("SELECT nid FROM {node}")->fetchCol();
  pathauto_node_update_alias_multiple($nids, 'bulkupdate');

  // Delete the topics taxonomy aliases.
    ->condition('source', 'taxonomy/term/%', 'LIKE')

  // Regenerate the taxonomy aliases.
  $tids = db_query("SELECT tid FROM {taxonomy_term_data} where vid = 8")->fetchCol();
  pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
Categorized as Drupal7

By Sam

Drupal developer from Perth, Western Australia. I love programming, gaming, the Internet, growing vegetables and hiking.

Leave a comment

Your email address will not be published. Required fields are marked *