4

I'm currently working with a client and running some scripts to generate reports (orphaned pages, etc). Right now, I need a way to get all possible registered aliases for a node. Right now, I'm using

$node = node_load($nid, NULL, TRUE);
$nurl = 'node/' . $nid;
$alias = drupal_get_path_alias($nurl);

I'm realizing, though, that the client has more than several pages where multiple aliases lead to the same node. Is there a function to retrieve an array of possible aliases?

Thanks!

2
  • There is PROBABLY a module to do this, but I've never looked for one. Hell, it seems to me there may even be a way that's built in to core to do this... but again, I've never seen it in my travels. If I was going to do this, I'd do it using: api.drupal.org/api/drupal/includes!database!database.inc/… ... the $node object will have the Drupal URL. You should be able to query url_alias.source for a any matching "alias" results. – jdu May 27 '14 at 18:03
  • I've created a module to show all URL aliases for a given page: drupal.org/sandbox/artem.kolotilkin/2503121 Check it out! – temkin Jun 14 '15 at 5:07
4

You can do it with a database query

$aliases = db_query('
  SELECT alias
  FROM {url_alias}
  WHERE source = :source
', array(':source' => 'node/' . $nid))->fetchAll();

You may need to modify things a little if you have a multilingual site to take the language column into account.

1
  • This is actually exactly what I had planned on doing unless someone else came up with a better answer :D – Josh Toth May 27 '14 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.