How to get post slug from Drupal database

I’m trying to export Drupal posts over to WordPress (which is in itself a hassle). I can’t figure out how to maintain the URLs of the blog posts though. Some of them are customized:

Blog titled Story of Soil is blog/2012/03/03/soil-story in Drupal. One titled Welcome John Doe is simply /john

Read More

Is there a Drupal function to making these URLs? Where does it store the customized blog posts?

Related posts

Leave a Reply

4 comments

  1. You should be able to get the Alias for a node by using drupal_lookup_path:

    // alias: return an alias for a given Drupal system path (if one exists).
    $alias = drupal_lookup_path('alias', $node->nid);
    

    Drupal manual: drupal_lookup_path or the reverse, look up node/internal path from alias: drupal_get_normal_path.

    It seems the url function function that Rawkode posted does about the same, so I guess it comes down to your personal preference.

    Also see: http://daipratt.co.uk/how-to-get-the-path-of-a-node-from-the-node-id-in-drupal/

  2. I found the above tremendously helpful because i was hoping to get what I needed from the db when I was looking and not by using a function. it gave me a good starting point but running this as it sits does nothing but error out because those are not the right column names. Keep in mind this updates stuff in place and will break everything if you are not working on a copy of the database. This code will fix it:

       UPDATE `url_alias` 
       SET source=SUBSTRING_INDEX(`source`, '/', -1), 
           alias=SUBSTRING_INDEX(`alias`, '/', -1) 
       WHERE 1
    

    since im not big on doing things in place I just added two columns nid and slug and then ran this query

       UPDATE `url_alias` 
       SET nid=SUBSTRING_INDEX(`source`, '/', -1), 
           slug=SUBSTRING_INDEX(`alias`, '/', -1) 
       WHERE 1
    
  3. I found the url_alias table in the Drupal database, and I ran this SQL statement:

       UPDATE `url_alias` 
       SET src=SUBSTRING_INDEX(`src`, '/', -1), 
           dst=SUBSTRING_INDEX(`dst`, '/', -1) 
       WHERE 1
    

    src is now the nid and dst is now the slug. I can rename them and then INSERT INTO wp_posts as post_name