Migrating from Drupal (4.7) to Wordpress

by Dave Dash 19May06

I helped Katie setup her new blog this weekend and decided that [WordPress] offers much of what I want out of this blog for a lot less effort than drupal[1]. I decided it might be worth my time to now while this blog is in it's infancy to try converting from drupal to WordPress.

The way I start most of my projects is with a plan:

I'm really confident that this will be easy. I don't even have to worry about comments or anything, since this blog is pretty new, but I can demonstrate how to take care of the.

Discovery

This post details a migration path from drupal to wordpress. Some considerations had to be made since I'm using [drupal] 4.7.

Implementation

Copy content

I followed most of the instructions, with some alterations from vrypan.net.

I installed [WordPress] and in mysql ran the following commands:

use wordpress;
delete from wp_categories;
delete from wp_posts;     
delete from wp_post2cat;
delete from wp_comments

I run my [drupal] site in the same database server, so the data copying was a snap. If you aren't so fortunate, just copy the relevant drupal tables temporarily your wordpress database.

First we get the [drupal] categories into [WordPress]:

USE wordpress;

INSERT INTO 
    wp_categories (cat_ID, cat_name, category_nicename, category_description, category_parent)
SELECT term_data.tid, name, name, description, parent 
FROM drupal.term_data, drupal.term_hierarchy 
WHERE term_data.tid=term_hierarchy.tid;

Again with the posts:

INSERT INTO 
    wp_posts (id, post_date, post_content, post_title, 
    post_excerpt, post_name, post_modified)
SELECT DISTINCT
    n.nid, FROM_UNIXTIME(created), body, n.title, 
    teaser, 
    REPLACE(REPLACE(REPLACE(REPLACE(LOWER(n.title),' ', '_'),'.', '_'),',', '_'),'+', '_'),
    FROM_UNIXTIME(changed) 
FROM drupal.node n, drupal.node_revisions r
WHERE n.vid = r.vid
    AND type='story' OR type='page' ;

And the relation between posts and categories:

INSERT INTO wp_post2cat (post_id,category_id) SELECT nid,tid FROM drupal.term_node ;

And finally comments:

INSERT INTO 
    wp_comments 
    (comment_post_ID, comment_date, comment_content, comment_parent)
SELECT 
    nid, FROM_UNIXTIME(timestamp), 
    concat('',subject, '<br />', comment), thread 
FROM drupal.comments ;

I ended up moving the one static page I had into [WordPress]'s "pages" section manually.

Since my pages are written in [Markdown], I enabled the Markdown for WordPress plugin.

URLs

Now for the real test. I needed to go through each page on my site and see if I could get to it using the same URLs. Since I had only 14 posts, I did this somewhat manually. I used [drupal]'s built in admin to do this from most popular to least popular. Most URLs worked fine. There were a small number that didn't for various reasons, I used custom mod_rewrite rules to handle them.

Adjusting Templates

My [drupal] template was fairly clean and simple. So I adjusted the CSS for the default theme in [WordPress] until I got what I liked. Very minimal changes had to be made to the actual "HTML."

Make the switch

Well, time to make the switch. In the WordPress administration, I just had to tell it that it's now going to be located at spindrop.us. Then I moved my [WordPress] installation to the [spindrop.us] web root. It was a snap. Let me know if you have any troubles.

<hr/>
  1. Taxonomy, legible URLs and trackback support all seemed quite difficult to master in Drupal. In Wordpress they appeared to be available standard or with a minor change in the administration panels.
  2. This is a prime reason why URLs should be clean and make sense to the end user, not the programmer of the publishing software.


Where am I?

This is a single entry in the weblog.

"Migrating from Drupal (4.7) to Wordpress" is filed under programming and reviewsby.us. It was published in May 2006.

May 2006
M T W T F S S
« Apr   Jun »
1234567
891011121314
15161718192021
22232425262728
293031  

Tags

need more help

If you found our tutorials and articles to be useful, but are still looking for more hands on help, consider hiring us. Find out more about how Spindrop can help you.

 

38 Responses to “Migrating from Drupal (4.7) to Wordpress”


  1. 1 zell Posted May 31st, 2006 - 9:53 am

    When going with the posts (INSERT INTO wp_posts …) i receive this error:

    #1052 – Column ‘nid’ in field list is ambiguous

    please, anyone knows how to solve it?

  2. 2 Dave Dash Posted May 31st, 2006 - 1:29 pm

    zell:

    Did you do this query exactly?

    INSERT INTO 
        wp_posts (id, post_date, post_content, post_title, 
        post_excerpt, post_name, post_modified)
    SELECT DISTINCT
        n.nid, FROM_UNIXTIME(created), body, n.title, 
        teaser, 
        REPLACE(REPLACE(REPLACE(REPLACE(LOWER(n.title),' ', '_'),'.', '_'),',', '_'),'+', '_'),
        FROM_UNIXTIME(changed) 
    FROM drupal.node n, drupal.node_revisions r
    WHERE n.vid = r.vid
      AND type='story' OR type='page' ;
    

    Note how I have n.nid and not just nid? That should clear the ambiguation.

  3. 3 jfish Posted June 4th, 2006 - 11:00 pm

    Thanks,It works great!!

  4. 4 Michelle Posted April 22nd, 2007 - 12:17 am

    How do you migrate Drupal Users to Wordpress?

  5. 5 Dave Dash Posted April 22nd, 2007 - 7:10 am

    Michelle,

    Unfortunately I don’t have an exact sql query, but try something like this:

    INSERT INTO wordpress.users (ID, user_login, user_pass, user_nicename,
    user_email, user_registered, display_name)
    SELECT uid, name, pass, name, mail, FROM_UNIXTIME(created), name
    FROM blog.users
    WHERE uid > 1;
    

    I found it on another site. If this query doesn’t work, it should with minimal tweaking.

  6. 6 Michelle Posted May 11th, 2007 - 9:14 pm

    Excellent and easy to follow tutorial, but you forgot the Users and Groups. What is the sequel code to transfer those over?

  7. 7 Dave Dash Posted May 11th, 2007 - 9:18 pm

    Michelle, try the code I posted in the comments, it might need some tweaking so prepare to do some backups/rollbacks

  8. 8 Jeff S. Posted June 24th, 2007 - 7:10 am

    Hello- I’m trying to use this script, and it doesn’t seem to work. When it says use “wordpress” and “drupal” in the script, am I supposed to replace those words with the actual name of the wordpress and drupal databases? I”m confused.

    Thank you, Jeff

  9. 9 Dave Dash Posted June 24th, 2007 - 12:56 pm

    Jeff,

    Yes, you need to use your actual database names.

    I strongly urge you to fully understand these scripts before executing them. If that means learning some SQL syntax, it’ll be for the best.

  10. 10 Jeff S. Posted June 25th, 2007 - 1:23 pm

    Thank you, everything worked, except for the users. I wish there was a way to import those, but every other site that has drupal-to-wordpress directions also don’t work for me.

    What version of Wordpress did you use when doing this? Thank you again, Dave.

  11. 11 Jeff S. Posted June 25th, 2007 - 11:45 pm

    At the insert posts option, I received this error “#1062 – Duplicate entry ‘3′ for key 1.” I used wordpress 2.01 because that was the version that was out when you made this post. I wonder what the error means?

  12. 12 Dave Dash Posted June 26th, 2007 - 10:31 am

    Jeff,

    I used the 2.x series. I suggest using the latest one even though you are right I prolly just used 2.01.

    As for the duplicate error, it may be safe to ignore, it probably just means you have the same ID for a post. You can also clear out the destination table and try again.

  13. 13 celia Posted June 30th, 2007 - 12:53 pm

    any ideas about how to import from wordpress to publicsquare?

  14. 14 Michelle Posted August 26th, 2007 - 12:22 pm

    I got everything converted, but I’m having a devil of a time getting the Users over. When I use the script I get various error messages with the Unix Timestamp code (whether I leave it in or take it out) and if I use the code exactly as is, it won’t let me insert – here I’m assuming it’s because I’m already the default wordpress User at 1. Any suggestions? I’m on Drupal 5.1.

  15. 15 Exo Posted January 8th, 2008 - 10:38 pm

    The topic is exactly what i want to do. however, first, i have my drupal site hosted with Godaddy. Godaddy provides phpMyAdmin 2.9.1.1 interface which allows my to backup or restore DB. Second, I have already backed up my ddrupal db. I have also installed Wordpress in a subdomain with a fresh new database.

    Now…i am not sure what to do next. I know practically nothing about mysql. I logged into phpMyAdmin 2.9.1.1 but not sure what to enter and where (referring to your instruction above).

    Could you help or give some pointers…please?

    Thanks in advance.

    -exo

  16. 16 Dave Dash Posted January 9th, 2008 - 1:37 am

    exo,

    I strongly recommend learning at least enough SQL and about PHPmyAdmin to be be confident, just so your not doing this blindly.

    Everything mentioned here can be done using phpMyAdmin. What you’ll want to do is first backup your database.

    You can then run these commands by clicking on an SQL tab once you’ve selected your database in phpMyAdmin. THe SQL tab will either give you a popup or a new page with a textarea that you can populate with one or more commands.

    In your situation I recommend doing one command at a time, lest you run into errors.

    Hope this helps you somewhat. Best,

    -d

  17. 17 George Posted January 19th, 2008 - 1:55 am

    Hi, I visited your blog just now. Very nice. Thanks! Best Articles Site

  18. 18 Zim Posted April 27th, 2008 - 6:21 pm

    Thank you very much. I went through hell with my phpMyAdmin and based on this post I made it! :)

  19. 19 Fuzzie Posted August 19th, 2008 - 9:19 pm

    I need to convert a Drupal theme (it is fairly basic, I created it with the Drupal Theme Generator) to a WordPress Theme, and I am having a very hard time figuring out how to do it. Can you help or point me in the right direction?

  20. 20 flaw Posted September 29th, 2008 - 7:09 am

    I dont think its too hard, you can take already converted themes and change them.

Who's linking?

  1. 1 .. Pingback on Jun 2nd, 2006
    "[...] Well, I’ve spent a good part of the past few days converting my site from Drupal to WordPress. The ... "
  2. 2 simplemente fidojones» Blog Archive » Cambio de drupal a wordpress Pingback on Jul 4th, 2006
    "[...] Aunque se que a algun amigo mio y no quiero mirar a nadie, no le ha gustado que me ... "
  3. 3 In Nomine… » Blog Archive » Moved to WordPress 2.0 from Drupal 4.6 Pingback on Jul 29th, 2006
    "[...] Conversion was not too hard. I followed directions as posted on http://spindrop.us/2006/05/19/migrating-from-drupal-47-to-wordpress and only had to change some things. ... "
  4. 4 jfish » 新版BLOG试运行 Pingback on Aug 18th, 2006
    "[...] 从Drupal迁移数据到Wordpress并不困难,只需要简单的SQL语句就可以搞定,并不需要去写专门的转换程序。我主要参考的是这篇文章,按照此方法操作存在一个问题,就是需要确保你的数据库是支持UTF8的,因为Drupal4.7的升级工作需要对数据库的字符集做UTF-8的转换。J虚拟空间的数据库是Mysql4.0版本,并不支持,所以我选择将数据导出,在本地使用新版的Mysql数据库,完成Drupal的升级工作。接下来,你就可以按照上面那篇文章一步步进行转换工作了,切记做一些操作前备份你的数据库,虽然会显得麻烦,但是这确实是一种稳妥的做法,很可能会给你节省不少时间。 [...] "
  5. 5 JonHoweOnline » CMS Switchover Pingback on Aug 31st, 2006
    "[...] I used the guide at spindrup.us to convert my database from drupal to be used with wordpress. You can ... "
  6. 6 el_anhelo_constante » Blog Archive » Parrulo 3.0 Pingback on Sep 1st, 2006
    "[...] Pues a pesar de no existir soporte para ello, ha sido mucho más fácil de lo esperado la tarea ... "
  7. 7 Slant Truth » My Adventures in Migrating From Drupal to Wordpress Pingback on Sep 14th, 2006
    "[...] I found a handful of sites that documented their migration from Drupal to Wordpress and I want to give ... "
  8. 8 The PhoneBoy Blog » Next Stop: WordPress! Pingback on Dec 6th, 2006
    "[...] I found a nice little article on how to convert Drupal to WordPress. Drupal is very nice in some ... "
  9. 9 Ismail Fahmi » Migrasi dari Drupal ke WordPress Pingback on Dec 20th, 2006
    "[...] Di Internet ada beberapa situs yang menyediakan teknik migrasinya. Saya ambil saja salah satu tips yang disediakan oleh Spindrop. ... "
  10. 10 Mac User Group Linz, Austria » Blog Archive » Todo Pingback on Jan 2nd, 2007
    "[...] http://spindrop.us/2006/05/19/migrating-from-drupal-47-to-wordpress [...] "
  11. 11 mason garden » Drupal 4.6 to Wordpress migration Pingback on Jan 25th, 2007
    "[...] On the off chance the someone somewhere will find it useful, I’m posting the SQL script I used to ... "
  12. 12 keyboardsamurais.de Trackback on Feb 23rd, 2007
    "keyboardsamurais.de migrated from drupal to wordpress... …and I have to say it was a tough ride. First off I’d like to ... "
  13. 13 graemef.com » Blog Archive » Drupal dumped, new life with WordPress begins Pingback on Sep 4th, 2007
    "[...] I managed to keep (most of) the content. I used these SQL snippets to migrate the posts, categories and comments, ... "
  14. 14 (we)blog » Миграция от Drupal 5.5 към WordPress 2.3 Pingback on Jan 28th, 2008
    "[...] http://spindrop.us/2006/05/19/migrating-from-drupal-47-to-wordpress [...] "
  15. 15 Step Into the Nexus » Blog Archive » Looking a Little Different Pingback on Jul 6th, 2008
    "[...] was one of the posts, but it needed a little tinkering because it assumes that your Drupal and Wordpress ... "
  16. 16 Importing Content another blogs to Wordpress | Guide for Blogs and Wordpress Pingback on Oct 15th, 2008
    "[...] Detailed migration of Drupal 4.7 to WordPress [...] "
  17. 17 Converting from Drupal 5.5 to Wordpress 2.7.1 | andremiller.net Pingback on Mar 19th, 2009
    "[...] used parts of the SQL script that Dave Dash, D’Arcy Norman and Mike Smullin worked on and  made a ... "
  18. 18 Learning The Hard Way : Performancing Pingback on Jul 11th, 2009
    "[...] Drupal installation into WordPress. The results are few and far between. I did find a MySQL script here and ... "
Comments are currently closed.

Further Help

If you require more hands on assistance, we do offer affordable hands on support.