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.
In case somebody is interested, a free Java version of a “migration script” to go from Drupal to WordPress is available here: http://modeling-languages.com/migrating-drupal-6-to-wordpress-3/
Quick question that I haven’t been able to find an answer to yet. Do I need to export ALL of my Drupal database tables, or can I limit it to certain ones? After looking at the ones in this code, I see that they match up consistently to my largest tables on Drupal (term_data, node, etc.).
The site I am trying to work on was started by someone even more inexperienced than me. Now it is being hammered by spam, which is affecting spam filters, search indexes, etc. By limiting it to certain tables I can cut the export down to one/third of the full size. Any idea if this will work?
Hi Brian, the script will only bring over tags, comments and nodes. Its won’t touch anything else like search indexes or cck fields. If you have spam in your node or comment table you could delete these records manually before running the import scripts.
Probably a bit late now but have you tried mollom to stop spam in Drupal?