Convert Drupal site to WordPress


The following article was based on successful experience during Convert Drupal site to WordPress. Please pay attention that no plugins related were moved, only pure nodes table with all data.
To Convert Drupal site to WordPress, I would recommend strongly to prepare a demo site on local machine using Xamp, Wamp or any other tool to simulate PHP, MySQL and Apache for testing.
Convert Drupal site to WordPress also requires backing up both SQL Data base and all folders and files on Drupal site.

To create a new WordPress site locally:

  1. Install WAMP on local machine.
  2. Go to PHPMyAdmin < create a new database that will be used to WordPress installation < name the Database” WPDB”.
  3. Install the WordPress and create a new site.

To backup and restore Drupal database to WordPress site:

  1. Go to PHPMyAdmin on Drupal site < select the appropriate Database on which Drupal work on< export all SQL database to *.SQL file.
  2. Zip the SQL file exported.
  3. Go to PHPMyAdmin on WordPress site  < select the database holds the WordPress site < click the import menu < choose the zipped Drupal site database backup and import (it may take few minutes 0 depending on your SQL file size and table structure).

So now we have new WordPress site installed connecting to a database that holds table for both new WordPress site and former Drupal site. Now we have to copy all nodes from Drupal to WordPress tables so normally you should see all Drupal tables with additional new WordPress tables (starts with _WP) :
wp_comments | wp_links |wp_options wp_comments |wp_links |wp_options |wp_postmeta
wp_posts |wp_ratings |wp_terms |wp_term_relationships |wp_term_taxonomy |wp_usermetwp_users.

The following step for copying all Drupal nodes to WordPress nodes involves SQL queries.
Running SQL queries under PHPMyAdmin can be done on the SQL tab inside the selected database.

To clear the WordPress tables run the follow query:
TRUNCATE TABLE WPDB.wp_term_relationships;
TRUNCATE TABLE WPDB.wp_term_taxonomy;

To import all taxonomy terms run this query:
INSERT INTO WPDB.wp_terms (term_id, `name`, slug, term_group)
d.tid,, REPLACE(LOWER(, ‘ ‘, ‘-‘), 0
FROM WPDB.term_data d
INNER JOIN WPDB.term_hierarchy h
INSERT INTO WPDB.wp_term_taxonomy (term_id, taxonomy, description, parent)
d.tid `term_id`,
‘category’ `taxonomy`,
d.description `description`,
h.parent `parent`
FROM WPDB.term_data d
INNER JOIN WPDB.term_hierarchy h

To import all node content (very important, here you should see query result as the numbers off post copied).
WPDB.wp_posts (id, post_date, post_content, post_title,post_excerpt, post_name, post_modified)
n.nid, FROM_UNIXTIME(created), body, n.title, teaser,
REPLACE(REPLACE(REPLACE(REPLACE(LOWER(n.title),’ ‘, ‘-‘),’.’, ‘-‘),’,’, ‘-‘),’+’, ‘-‘),
FROM WPDB.node n, WPDB.node_revisions r
WHERE n.vid = r.vid

If categories where in use on Drupal site, use the following queries:

To connect posts to categories run this:
INSERT INTO WPDB.wp_term_relationships (object_id, term_taxonomy_id)

SELECT nid, tid FROM WPDB.term_node;

To update category count:
UPDATE wp_term_taxonomy tt
SET `count` = (SELECT COUNT(tr.object_id)
FROM wp_term_relationships tr
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id);

To update comments count on WordPress posts:
UPDATE `wp_posts` SET `comment_count` = (SELECT COUNT(`comment_post_id`) FROM `wp_comments` WHERE `wp_posts`.`id` = `wp_comments`.`comment_post_id`);

To fix posts content:
UPDATE WPDB.wp_posts SET post_content = REPLACE(post_content, ”, ”);

Last checking:

  1. Check your new WordPress site under posts and see that you get all the post with attributes right.
  2. If needed, posts can be easly changed to pages in WordPress using the following SQL query inside the WordPress DB:
    update wp_posts set post_type = ‘page’ WHERE post_type = ‘post’

After checking that all works fine- delete the old Drupal tables imported one by one from database.