• Stay in touch. Sign up for the 9seeds newsletter.
  • Drupal to WordPress migration

    A client came to us this week with a problem; he had a Drupal site with over 1000 articles that he wanted to convert to WordPress. So we headed to Google for some help. There are several tutorials out there on how to migrate Drupal content to a WordPress site, but many of them are really outdated. After kicking the tires on a few, this post by Mike Smullin seemed to be the best jumping off point.

    Mike is right up front in his instructions with the fact that you’ll need to do a bit of tweaking to his set of instructions to get it to work for your setup. After a few failed attempts, we came up with an updated set of instructions. We’ve included the updated version along with notes about changes made.

    These instructions are a set of SQL statements. It assumes you have a database named WordPress using ‘wp_’ as the prefix and another database named Drupal.

    This should go without saying, but I’ll say it anyway; do not move forward without backing up your databases FIRST!

    Clear all existing WordPress content

    1
    2
    3
    4
    5
    6
    7
    
    TRUNCATE TABLE wordpress.wp_comments;
    TRUNCATE TABLE wordpress.wp_links;
    TRUNCATE TABLE wordpress.wp_postmeta;
    TRUNCATE TABLE wordpress.wp_posts;
    TRUNCATE TABLE wordpress.wp_term_relationships;
    TRUNCATE TABLE wordpress.wp_term_taxonomy;
    TRUNCATE TABLE wordpress.wp_terms;

    Create Categories

    1
    2
    3
    4
    5
    6
    
    INSERT INTO wordpress.wp_terms (term_id, `name`, slug, term_group)
    SELECT
     d.tid, d.name, REPLACE(LOWER(d.name), ' ', '_'), 0
    FROM drupal.term_data d
    INNER JOIN drupal.term_hierarchy h
     USING(tid);

    Add Taxonomies

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    INSERT INTO wordpress.wp_term_taxonomy (term_id, taxonomy, description, parent)
    SELECT
     d.tid `term_id`,
     'category' `taxonomy`,
     d.description `description`,
     h.parent `parent`
    FROM drupal.term_data d
    INNER JOIN drupal.term_hierarchy h
     USING(tid);

    Import posts/pages
    We added ‘article’ to the array on the last line to solve an issue with the way Drupal had categorized the posts.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    INSERT INTO wordpress.wp_posts (id, post_date, post_content, post_title, post_excerpt, post_name, post_modified, post_type, `post_status`)
    SELECT DISTINCT
     n.nid `id`,
     FROM_UNIXTIME(n.created) `post_date`,
     r.body `post_content`,
     n.title `post_title`,
     r.teaser `post_excerpt`,
     IF(SUBSTR(a.dst, 11, 1) = '/', SUBSTR(a.dst, 12), a.dst) `post_name`,
     FROM_UNIXTIME(n.changed) `post_modified`,
     n.TYPE `post_type`,
     IF(n.STATUS = 1, 'publish', 'private') `post_status`
    FROM drupal.node n
    INNER JOIN drupal.node_revisions r
     USING(vid)
    LEFT OUTER JOIN drupal.url_alias a
     ON a.src = CONCAT('node/', n.nid)
    WHERE n.TYPE IN ('post', 'page', 'article');

    Turn articles in to posts
    This will turn the ‘articles’ from the previous step in to ‘posts’ in WordPress.

    1
    
    UPDATE wordpress.wp_posts SET post_type='post' WHERE post_type='article';

    Add post to category relationships

    1
    2
    
    INSERT INTO wordpress.wp_term_relationships (object_id, term_taxonomy_id)
    SELECT nid, tid FROM drupal.term_node;

    Update category count

    1
    2
    3
    4
    5
    
    UPDATE wordpress.wp_term_taxonomy tt
    SET `count` = (
     SELECT COUNT(tr.object_id)
     FROM wordpress.wp_term_relationships tr
     WHERE tr.term_taxonomy_id = tt.term_taxonomy_id);

    Import comments

    1
    2
    
    INSERT INTO wordpress.wp_comments (comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url, comment_approved)
    SELECT nid, FROM_UNIXTIME(TIMESTAMP), comment, thread, name, mail, homepage, STATUS FROM drupal.comments;

    Update comment counts
    After fighting with the original syntax, I added the ‘use wordpress’ step to get around it.

    1
    2
    
    USE wordpress;
    UPDATE `wp_posts` SET `comment_count` = (SELECT COUNT(`comment_post_id`) FROM `wp_comments` WHERE `wp_posts`.`id` = `wp_comments`.`comment_post_id`);

    Fix breaks in post content

    1
    
    UPDATE wordpress.wp_posts SET post_content = REPLACE(post_content, '', '');

    Fix images in post content

    1
    
    UPDATE wordpress.wp_posts SET post_content = REPLACE(post_content, '"/files/', '"/wp-content/uploads/');

    If your posts have any images you’ll need to move them from your ./files directory to the ./wp-content/uploads directory. The final step above should take care of fixing any image calls in your pages and posts, but you still may need to manually update them if you are having issues.

    Download a copy/paste friendly version of the Drupal to WordPress instructions here.

    if you have any questions, leave us a comment below.

    OMG, we’re a year old!

    It’s hard to believe it was one year ago today that Todd, Shayne and I set out on this journey together. A year already? How is that even possible?

    I’ve been asked several times how 9seeds started. So for those who have wondered but never asked, here’s a quick history of how 9seeds came to be.

    Back in 2008 I had heard about a series of events going on around the country called WordCamp. I sent a message on twitter asking if anybody was planning one for Las Vegas. The responses I got back all said pretty much the same thing, “no, but you should organize one.” Having never organized an event of this size before, I did what any (in)sane person would do, I dove in head first!

    In early January of 2009, WordCamp took place in Las Vegas. It came together far better than it should have given my lack of experience. A lot of that had to do with the amazing lineup of speakers that weekend. One of which was Shayne Sanderson. Though we had never met in person and had only chatted online a few times to that point, we became good friends right away.

    During that time, Todd and I were working for a marketing company here in Las Vegas. The owners had sold a large portion to an investment company and though we had both been there for several years our interest in staying there was quickly fading.

    Over the next several months, Shayne and I spoke at a handful of WordCamp events. This lead to both of us receiving several requests for side projects. Shayne and I were working nights and weekends as we both found no end to the amount of people looking for help. We started collaborating on more and more projects. When we needed extra help, we would hit up Todd.

    We weren’t happy with our day jobs and there were a slew of people looking to pay us for help. It didn’t take a rocket scientist to realize where this was going. Within a few months, we decided to start a company together.

    While October 1st is our “official” anniversary, last year at this time we all still had full time jobs. But that got old pretty quickly. By the end of January, we had all quit our jobs and have been building 9seeds ever since.

    We are amazingly lucky to have made so many friends in the WordPress community. It has been an amazing first year and we can’t thank you enough for your friendship and support.

    From the bottom of our hearts, thanks!

    - John