posted on Thursday, January 9th, 2014
I had a previous task of moving a database of a Drupal 7.1 website to a temporary WordPress 3.8 installation. Through roughly few hours of searching the web and testing scripts on my desktop (Environment: Windows 7 Professional, Apache 2.2.25, PHP 5.3.27, MySQL 5.6, phpMyAdmin 4.0.5, Drupal 7.10 [2011-12-05] database, and a fresh WordPress 3.8 installation), I got everything moved almost exactly as from the original Drupal site except for small details where the site created other post / page types besides ‘pages’ (e.g. it had ‘trip’, ‘webform’, ‘area_link’, etc.). To address this issue I had to implement some changes in my ‘Permalink’ and installed other plugins to maintain original links from Drupal to WordPress.
For this example / walk through, I set up my database names as ‘wordpress’ for WordPress 3.8 installation database and ‘drupal’ for the Drupal database imported to my local database server.
Substitute ‘wordpress’ and ‘drupal’ to your own database names.
Drupal Database to WordPress Database: Walk Through
- Make sure you have Drupal database has been restored in your database either through phpMyAdmin, MySQL Workbench or via command line.
- Prepare your freshly install WordPress 3.8 database by truncating default posts / pages / comments after installation. Paste and run query below in phpMyAdmin or on your MySQL Browser:
- Depending on your source database if you have a number of users to migrate you may need to run the following scripts, otherwise you can skip this step:
- Migrate tags:
Migrate taxonomy terms / vocabulary:
- Copy over your Drupal posts to your WordPress database. Note that the issue I raised before can be seen here. The all post types will be inserted to your destination database:
Note that the fields to_ping, pinged, post_content_filtered have been added to the insert query since error shows they have ‘no default value’ when we try to run the script.
If you would like to see all copied posts in your WordPress just simply run this script:
- Update post to tag / category relationship:
Update tags / category post count:
- Insert comments to posts, if your original website database have disabled comments or use third-party commenting solutions lke Disqus, you won’t need to run these scripts:
Update post comments count:
- The following code is suppose to help fix taxonomy – that is if it was set up correctly in the original Drupal site.
- Insert authors to your database, note that your admin account has already the ID ‘1’, therefore users table from drupal is filtered only with IDs greater than ‘1’. Otherwise if you have no other users in your Drupal database, you can already skip this step:
Asign author roles / permissions to users:
Assign and give administrator rights / privileges:
- We are not quite finished yet. If you’ll need to move you Drupal images and files inside your WordPress as I did, I created an ‘uploads’ folder in wp-content, then ‘old’ to have ‘/wp-content/uploads/old/’ and copy all Drupals files, images etc from ‘/sites/default/files/’ and then fix image and file urls with this script:
- Finally, we can fix permalinks by using plugins such as ‘Permalink Editor’ to customize page / post urls. There are also other plugins where you can customize tags and categories slugs too.