Moving from Drupal 6 to WordPress 3.1

I thought it was about time I updated my site as it was running as a Drupal 6 install. I wanted to concentrate on the blogging aspect of the site and thought that WordPress might be closer to what I needed from a CMS.

So here is how to convert a drupal site to wordpress.

1) Back up the database.

2) Install a fresh version of wordpress onto the same mysql server as the drupal database with the database name of “wordpress”.

3) Open a mysql client and make your drupal database the currently selected database.

4) Paste the following and execute.


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;

INSERT INTO wordpress.wp_terms (term_id, `name`, slug, term_group)
SELECT
 d.tid, d.name, REPLACE(LOWER(d.name), ' ', '-'), 0
FROM term_data d
INNER JOIN term_hierarchy h
 USING(tid)
;

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 term_data d
INNER JOIN term_hierarchy h
 USING(tid)
;

INSERT INTO
    wordpress.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 node n, node_revisions r
WHERE n.vid = r.vid and n.type = 'blog'
;

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

;

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
);

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 comments;

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

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

UPDATE wordpress.wp_posts SET post_content = REPLACE(post_content, '"/sites/default/files/', '"/sites/default/files');

5) You then just need to copy all your files from the drupal /sites/default/files to /sites/default/files

This worked exceptionally well for my site and because its just a sql script it runs quickly. I got the script originally from this link and have only edited it together and changed the database names. http://www.smileyouroncamera.co.uk/2011/09/30/migrating-drupal-based-site-to-wordpress.