How To Convert Drupal To WordPress

convert drupal to wordpressAfter hunting down some tutorials and finding some missing important parts, no explanations, and being disappointed, I had to do some experimenting. As a developer, I do not mind solving a challenge and putting puzzles together. There were some decent tutorials, however, I found that once I completed my own Drupal to WordPress conversion, I needed to share the process in the easiest way possible.

Please note that that this tutorial to convert Drupal to WordPress is not giving you the goods on how to convert your stat counters over, if you need to make sure your Disqus comments match up (in the case you use Disqus instead of the content management system’s native comments), or special modules that are storing information in the database. You will need to seek building a extended custom plan for you to convert Drupal to WordPress.

Some of the issues I ran into were questions that other developers had with whether tables could be converted over as well as users. In fact, a lot of the questions I saw were over the user conversion from Drupal to WordPress. Also, this was a problem that was not addressed in some of the tutorials. Some of the scripts did not properly work, or did not have anything about converting over users.

I found issues with the categories and tags not being translated over to the correct taxonomy when doing my conversion. In fact, they were all slopped into the tags. My solution is before converting to make sure in the original Drupal install that these taxonomies are correctly labeled. Tags are non-hierarchical and Categories are hierarchical.

Another big problem was running into duplicate errors when feeding the SQL through the conversion process. The solution for this was to check the last known table that was converted over and only convert from after that table. It was tedious, especially since my conversion was for 17,000 posts and over 2,500 users. What a way to break in figuring out how to convert Drupal to WordPress, right?

This post goes over how to convert Drupal to WordPress, mostly the core the database (like posts, post meta, taxonomies, and post types, users, and comments), and a little bit about converting the theme. Note: This will work for converting up to the latest version of Drupal to the latest version of WordPress, as of August 1, 2014.

Convert Drupal To WordPress: The Database

1. Export the Drupal SQL file from the old host.

2. Install a fresh new WordPress site. You need to clear the tables with the TRUNCATE command by going into your database’s SQL queries tab in phpmyadmin. The code is:

Replace the wordpress before the period with the database table name before executing the query. In the case you are doing the query from that WordPress database directly, you do not need the wordpress and the period in the code when executing the script.

3. If you have multiple users to convert over, you will need to use the following code.

Again, replace the wordpress before the period with the database table name before executing the query.

4. The following query will convert over tags:

5. The following converts over posts.

Please note that if your Drupal installation has several post types, you will want to add the name of the post type into the to the line that says WHERE n.type IN (‘post’, ‘page’, ‘blog’). If you do not add all post types, then not all will be converted over.

6. In the case you want to combine post types in WordPress. Say you wanted post and blog together, you would put the following code:

7. The following code defines the post/ tag relationship

8. The following code is for comments:

9. If you are keeping your Drupal images and filed in the same place, you do not have to do anything. However, if you are FTP-ing your files to the uploads folder in your WordPress wp-content folder, you will want to use the following script to fix the URLs to the images.

10. The following code is suppose to help fix taxonomy… that is if it was set up correctly in the original Drupal site.

11. Author roles for your users:

This sets the author role’s permissions.

You may want to uncomment (remove the number sign) before the line that has the email address and put your own in so your role remains as an administrator.

12. Assign and give administrator status.

13. The following code helps assign authors to the posts they wrote.


UPDATE wordpress.wp_posts
SET post_author = NULL
WHERE post_author NOT IN (SELECT DISTINCT ID FROM wordpress.wp_users)
;

14. Depending on how the original Drupal site has been set up, sometimes the URLs are funny, try feeding the following query. It does not hurt to try.

15. The following is some extra clean up for the editor so your posts do not look too funky from the conversion.

There are quite a few other options, but I found these the most necessary for my install. In the case you want to look through for more options, you can check out the Drupal to WordPress Migration at the Underdog of Perfection.

I did run into one last thing that was a problem. Once I had everything over, I went to click on the individual posts and pages. I did already set the permalinks to postname. However, the links kept redirecting back to the home page. I had to update the slugs.

To do so, you need to put the following code in the wp-config.php file before the ending PHP tag. Once you have, click save and then reload the front of your site. The script will run and should not take long at all. Once the front of your site loads, go back into the wp-config.php file and remove the code.

Convert Drupal To WordPress: The Theme

If you are familiar with, HTML, PHP, CSS, WordPress theming, and Drupal theming, great! Most people usually write about how to convert Drupal to WordPress, and not talk about the theme conversion, especially for those who love their theme and just want to switch the content management system. You should know that the concepts of theming in WordPress are similar in Drupal. You design the theme, and in the parts that you want WordPress to do the work, like pages, posts, and widgets, you place the code with the coordinating loop and dynamic sidebar PHP call to those areas. If you are not familiar with theming, you can refer to my podcast presentation that includes a slideshow on PSD to WordPress, which delves a little deeper into WordPress theme templates.

You can literally remove all the codes for modules and such from the Drupal theme templates and replace with the WordPress code.

I hope this helps explain the steps to convert Drupal to WordPress. Please use at your own risk and always have a back up before you remove anything for good.

Comments

  1. says

    Hi Nile,
    thank you very much indeed for these easy-to-use steps and clear explanations. To be honest, I am fascinated with your ability to find simple words for explaining these complicared issues. Thank you very much once again.

  2. says

    Wow..i just can say that these kind of explanations are very very helpful. I work with WordPress and I was wondering if there was a way to convert WordPress to Drupal. Like you said, there are some tutorials but this explanation is very good and i like to hear it from you if it is possible. Tnx

    • says

      Hi Aleksandar! I am pretty sure there is a way to do the opposite and much of it would most likely be using the same code above, but opposite on the query commands. However, I normally convert sites to WordPress, because it is much easier for people.

  3. says

    I heard that drupal was alo a big deal in the blogosphere, but I never used it, I won’t really be needing this since I rarely find look for any drupal themes

  4. says

    Oh My Gosh!

    I wouldn’t wish this on anyone. I don’t know nothin’ bout no Drupal and hope I don’t ever have to convert it to WordPress!

    But Thanks for sharing anyways!

    LOL!

    ~ Jupiter Jim

    (please delete the parentheses — Nile, don’t worrry, this ain’t my comment for the week. Just had to share this thought!)

  5. says

    Hmmm….converting from drupal to wordpress. The first thing you must do is BACKUP your drupal site before you try this. This is because something unpredictable could happen during conversion.

  6. says

    Hello,

    Thanks for the informative post. I will try the same and if will need any further guidance will approach you.

    Thanks and Regards,
    Nishant Desai | SEO Expert India

  7. says

    Thank you so much for this article! I right now use both Drupal and WordPress in their own separate worlds, but if I ever need to convert, I know where to go to! Bookmarked! Thanks again!!

  8. says

    Wow! Thank you so much.. you’re a real lifesaver. I had a client today who came to me with his Drupal site and a wanted me to edit the site for him, but I was totally clueless about Drupal. Got it converted to WordPress thanks to you! Keep on rocking :-)

  9. says

    Not familar with Drupal, looks like a nightmare doing this though. Some sites we have are Joomla sites and I’m not a fan. It’s more sophisticated but not as simple :-p

  10. says

    Whoa! Thanks a lot a great deal.. you’re a true lifesaver. I’d a customer at the moment whom located anyone together with his Drupal web site and a noticeably necessary anyone to switch the website meant for him or her, web hosts on the other hand I has been totally clueless concerning Drupal. Started using it turned into WordPress on account of somebody! Proceed rocking.

  11. Ellen says

    thanks for sharing this info! It’s awesome! the fact that you really share this instead of just keep it to yourself or make money…
    The truth is, I am not capable of doing anything more than publishing content on my Drupal site, cause I am afraid to break something (which happened several times already) But I’ve found a tool at http://www.cms2cms.com that migrates Drupal to WordPress like without any efforts on my site and for free (this is the weirdest thing:)
    Do you think I can try it?
    Sorry, but your wonderful script is something too complex for me to use…

    • says

      I am sure you can try it out. It seems to be in beta version. If you do try it out and it works great, let me know. :) Just make sure to have a backup of your original Drupal site before trying the migration. :)

      The script is one that is open source and worked for me from scripts that had some missing areas. I am just sharing my experience and hope it helps.

    • says

      That is no longer free. I tried it and it converted about 10 posts/users. Then asked me to pay $50 to convert more. After doing some research online someone else had to pay over $100.

      They just entice you to use the software, and then pressure you to pay after you get the conversion done at 25% or less.

      So Nile’s method is good to use as a free option, though I do know some people feel scared to even look or touch code.

      I also have a converter that does everything for you no coding skills required.

      I’m not allowed to post the link here, but you can always search google. If you know some code or feel okay with it then go with Nile’s route.

  12. says

    As wordpress provides all the features without any head ache of coding. I don’t have any idea about Drupal but I think wordpress is best at this time.

  13. says

    hello Nile..
    I never used drupal yet ,But I learn converting procedure for my future.May be this will be very helpful to me in future.Thanks for nice sharing.

  14. says

    I haven’t used drupal as I am always connect with wordpress. As it is the nice interface for blogging. Thanks for this tutorial for converting drupal to wordpress.

  15. says

    I am a new user to this blog. so informative. i learned few methods from your site. Drupal is another CMS like wordpress. but i am completely new to this. anyway it will be useful in future. i will practice with this. thank you

  16. Amy says

    Arghh… I wish I had come across this before moving my site over. I’ve already populated a lot in WordPress, but I still want to import my older Drupal articles into WP.

  17. says

    Hi – I am a newbie to wordpress. I’m happy to have found this tutorial but I have a really basic question. I want to make sure I follow the steps correctly.
    1) So When I export the Drupal database, I’m assuming that I I then import it to the fresh wordpress install? Or I make the truncation changes on the database before importing it to wordpess?

    • says

      You will want to have the drupal tables on the same web hosting account as your WordPress install before converting over… that is why you have to label your database tables properly in order to do the conversion. You don’t have to have the Drupal database in the same exact database as WordPress… just the same web hosting account’s MySQL. So if i were converting here, I’d more than likely put my drupal database in blondish_drpdb and convert it over to blondish_wrdp as an example.

      • says

        Thank you for the clarification. You are extremely helpful. But just to be sure…

        1) copy the original database and place it in the wordpress site.
        2) Does the fresh wordpress install have to happen AFTER putting the database there? I already installed WordPress.
        3) make of copy of that original database and make the changes to the new database as listed above – so that there is an original drupal database and a modified/converted wordpress database on the same site.

        Please excuse my “blondness” :) (I use to be anyway…)

        • says

          Hi Heather!

          You do not have to put the Drupal database into the same database as WordPress. You can create a new mySQL database and import the database through MySQL.

          However, if you do want to convert the Drupal database in the same one as WordPress, just import the sql or compressed sql file of the Drupal database into the WordPress one. Now, once you are done converting, you can select the Drupal tables and drop them. You may need to take notes on what tables to actually drop so you don’t accidentally delete a WordPress table.

          You don’t have to have a fresh install of WordPress when you are done converting, but like I said above, and recommend… remove the Drupal tables if you are indeed working in the same database account as your WordPress installation. I hope that helps.

  18. says

    Wait – so the first part – deleting the users greater than 1, doesn’t make sense to me. Why would I do that? Sorry… but I have the users already listed just fine so I don’t understand why I should delete them…

    • says

      This is to remove the users. If you have users in drupal, you will need to remove any that you have in WordPress except for 1, which is your admin. If you don’t have more than one, you can skip this step.

      • says

        The proper answer here is that you DO have to delete users >1. Why? because if you have a user with the user ID 2 in WordPress already and your drupal database has another user with a user ID 2. Then when you port over the drupal user2 it will either overwrite the wordpress user2 or it will not port that user over. In this case you now have a problem…..

        That’s why you need to delete the users on the wordpress end or better yet start WP from a fresh install. That way you’ll only have 1 user with the user ID 1.

  19. says

    I can call myself an expert in Drupal and PHP, but I haven’t worked on any conversions yet, as I do have a separate team working on stuffs like that.

    I will pass over this info to my team, might be of use in the future. But most of my customers come in to get converted to Drupal and not otherwise. But I loved reading this post as you are so precise with your steps in conversion.

  20. emilio says

    Hi there,
    I used your SQL to import the “posts” and “pages” into WordPress. When I go into wp-admin, everything is listed under pages, and nothing is under posts. In the wp-db, post_type correctly contains all the types from drupal, “blog, image, story, etc” any thoughts?

    Thanks!

      • says

        You could move the images to your uploads folder and change the links to direct the path there as per one of the steps. The only issue is that you will not be able to manage them in the Media Library unless you load them from the WordPress admin.

    • says

      You have to either register a custom post type in WordPress, OR, you will have to change in your Drupal database the line for the post type. blog and story are normally for post.

      • Emilio says

        Hi thanks for replying. But it doesn’t explain why everything is listed as a page in wp. What is the correct value for a “post” and “page”? In your code example above it might be useful to indicate that “WHERE n.type IN (‘post’, ‘page’, ‘blog’)” will certainly pull the content, but it won’t correctly produce posts in wp. wp expects post_type=’post’ to display as post and you’ll have to convert everything else to ‘post’ or register the custom post_types.
        Additionally, images are stored as:
        post_type=”attachment”
        guid=”URL”
        post_mime_type=”image/jpeg”

        Thanks for the article, it definitely helped jump start the process. :)

        • says

          If you don’t want blog, don’t put it in your MySQL. post_type for posts are ‘post’ and ‘page’ for pages. If you want other post_types like image or other, like blog, you can still carry those over, BUT… you are going to have to create a custom post type (register it in your themes functions.php or install the Custom Post Types UI plugin) for blog or story, or anything else.

  21. Victor says

    Hi,
    Looks like this is exactly what I need. However, I am not sure at what stage I should bring in the actual data from the exported Drupal .sql? Should this be the last step after all the SQL statements are run? If yes, shouldn’t this be pointed out in the article?
    On the third step I get “#1142 – SELECT command denied to user ‘my_user_name’@’localhost’ for table ‘term_data’ “.

    Thanks for your help.

    • says

      There are some scanners in WordPress that will grab from the original site and import. Right now, the Image Scanner plugin available in WordPress is old and only works on individual posts, and not the mass one. I’d like to see someone fork it over and work with it. I may try to fork the plugin over and hopefully it could help.

  22. says

    Thanks so much for the article.

    I’ve attached an updated sql query from inserting posts & pages from drupal 7 –> wordpress 3, for posterity’s sake.

    You’ll need to change one of the IF statement in the select clause to make sure the correct drupal node type turns into a post (our node type was “article” in drupal):

    INSERT INTO wordpress.wp_posts
    (id, post_author, post_date, post_content, post_title, post_excerpt,
    post_name, post_modified, post_type, post_status)
    SELECT DISTINCT
    n.nid id,
    n.uid post_author,
    FROM_UNIXTIME(n.created) post_date,
    rb.body_value post_content,
    n.title post_title,
    rb.body_summary post_excerpt,
    IF(SUBSTR(a.alias, 11, 1) = ‘/’, SUBSTR(a.alias, 12), a.alias) post_name,
    FROM_UNIXTIME(n.changed) post_modified,
    IF(n.type = “article”,”post”,n.type) as post_type,
    IF(n.status = 1, ‘publish’, ‘private’) post_status
    FROM drupal.node n
    INNER JOIN drupal.node_revision r
    USING(vid)
    INNER JOIN drupal.field_revision_body rb ON rb.entity_id = r.nid
    LEFT OUTER JOIN drupal.url_alias a
    ON a.source = CONCAT(‘node/’, n.nid)
    # Add more Drupal content types below if applicable.
    WHERE n.type IN (‘article’, ‘page’)
    ;

  23. Abdul Moiz says

    Hey,

    This is a great post, I am about to convert a very very heavy website to WordPress, I hope I can do it. Is there any way I can be in direct contact with your via Email or something like that.

    • says

      Hi Abdul! If you’re asking me to consult with you even through email for your Drupal to WordPress conversion, I do charge per hour – $50/hour flat rate. You’re welcome to use my contact form to ask, but I’m no longer answering questions via email for free because I’ve had to give up time in the past.

  24. Michele says

    Hi,
    I imported my drupal 7.25 directly into my wordpress 3.9 install. the wordpress wp is actually 5ma. The drupal tables have nothing in from of the names. I keep getting this error:

    #1054 – Unknown column ‘n.body’ in ‘field list’
    Please help!

    Here is my sql. accessed from phpmyadmin:

    INSERT INTO 5ma_posts
    (id, post_author, post_date, post_content, post_title, post_excerpt,
    post_name, post_modified, post_type, post_status)
    SELECT DISTINCT
    n.nid id,
    n.uid post_author,
    FROM_UNIXTIME(n.created) post_date,
    n.body post_content,
    n.title post_title,
    n.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 node n
    INNER JOIN node_revision r
    USING(vid)
    LEFT OUTER JOIN url_alias a
    ON a.src = CONCAT(‘node/’, n.nid)
    # Add more Drupal content types below if applicable.
    WHERE n.type IN (‘post’, ‘page’, ‘blog’)
    ;

    • says

      your name is wrong for your database table, which you are missing…. and you need the period before it. Usually if your converting, your converting to a fresh WordPress install with default tables

  25. Nitz says

    So I decided to code a converter after finding none out there. It’s pretty indepth since I was doing it for a clients website.

    I posted more details here if anyone is interested.

    • says

      I removed your link as it was posted in a forum. You need to put a website up. The directions in this tutorial are complete and still work even on Drupal 7.

      • says

        Your directions are complete, however the average person CANNOT go through the instructions. Most people do not know how to code or even edit the database name in your code.

        My code needs NO knowledge. You literally upload the files, run one file and it does everything. I made it automated so you literally hit enter and EVERYTHING get’s converted.

        Why would someone want to copy paste code and then have to edit it for the proper database when they can run 1 single file and convert all of their Drupal database to a WordPress database.

        I’m not going to open a brand new site and spend hundreds of dollars just to post a converter.
        I had linked you as a source in my program with a special thanks to you for inspiring me to do so.

        But, maybe I was wrong in doing so….. I think this is more about you losing hits more than it is to help others. But that’s fine, it is how it is…

        Google’s index will find my forum post at some point and people will no longer need to worry about having to copy and paste code.

  26. philip says

    thanks for the awesome tutorial. i am having a problem with converting the tags. whenever i run the queries i get the following error:
    Duplicate entry ’77-post_tag’ for key ‘term_id_taxonomy’

    any help is greatly appreciated.

    • says

      HI Philip. If the database your’re converting from is a duplicate of the original (I hope it is), go to the Drupal database and remove the tag giving the problem. Then run the query through again. This is like the issue I had with the posts giving a problem with the primary key. I’m thinking something got corrupted. You should still have the taxonomy, but you just need to remove it now in order to proceed.

      • philip says

        thanks for the help. unfortunately, i’m still having problems. but it’s okay, the client is only worried about the last 6 months worth of posts (which isn’t a lot) so they will just manually convert the tags.

        i did notice something, the SQL for steps 13 and 14 are the same. just thought you should know.

        thanks again for the help.

  27. says

    Hello Nile,
    I’m a designer from Miami, FL,
    I want to thank you for this post very illustrative and useful!! Thanks a lot!!
    I wonder if you could recommend me some effective guide for theming wordpress.?

  28. says

    Hi there, I’m trying to do this but I am having the HARDEST time getting it to work. Hoping you can please help me out…

    This is what I’ve done….

    1.) exported drupal database
    2.) set up a wordpress site
    3.) in myphp admin, Iv’e imported the drupal sql database

    now this is where I get stuck…

    4.) I’ve pasted the TRUNCATE tables (with this):
    # Empty previous content from database.
    TRUNCATE TABLE .wp_comments;
    TRUNCATE TABLE .wp_links;
    TRUNCATE TABLE .wp_postmeta;
    TRUNCATE TABLE .wp_posts;
    TRUNCATE TABLE .wp_term_relationships;
    TRUNCATE TABLE .wp_term_taxonomy;
    TRUNCATE TABLE .wp_terms;

    5.) when I try to paste the step 4 of your tutorial (even when removing the “wordpress” in front of the periods), I get the following error: MySQL said: Documentation

    #1142 – SELECT command denied to user ‘wordpress_5f’@’localhost’ for table ‘term_data’

    Can you please let me know what might be going wrong? Would be amazing to get this to work…

    • says

      It should work. Hopefully you didn’t add the drupal tables into the same database you were converting over, or it won’t work right.

Leave a Reply

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

CommentLuv badge