Guides‎ > ‎

Drupal to WordPress

# Changelog

# 02.06.2009 - Updated by Mike Smullin
# 05.15.2007 - Updated by D’Arcy Norman
# 05.19.2006 - Created by Dave Dash

# This assumes that both wordpress and drupal are in separate databases. The wordpress database is called "wordpress" and the Drupal database is called "drupal"

# first, nuke previous content in straticswp database
TRUNCATE TABLE straticswp.wp_comments;
TRUNCATE TABLE straticswp.wp_links;
TRUNCATE TABLE straticswp.wp_postmeta;
TRUNCATE TABLE straticswp.wp_posts;
TRUNCATE TABLE straticswp.wp_term_relationships;
TRUNCATE TABLE straticswp.wp_term_taxonomy;
TRUNCATE TABLE straticswp.wp_terms;

# categories
INSERT IGNORE INTO straticswp.wp_terms (term_id, `name`, slug, term_group)
 d.tid,, REPLACE(LOWER(, ' ', '_'), 0
FROM stratics.drupal_term_data d
INNER JOIN stratics.drupal_term_hierarchy h

INSERT IGNORE INTO straticswp.wp_term_taxonomy (term_id, taxonomy, description, parent)
 d.tid `term_id`,
 'category' `taxonomy`,
 d.description `description`,
 h.parent `parent`
FROM stratics.drupal_term_data d
INNER JOIN stratics.drupal_term_hierarchy h

# posts; keeping private posts hidden
# change to "INSERT IGNORE INTO ..." if running this query again (eg: you missed some custon "n.type IN (...)"

INSERT IGNORE INTO straticswp.wp_posts (id, post_date, post_content, post_title, post_excerpt, post_name, post_modified, post_type, `post_status`)
 n.nid `id`,
 FROM_UNIXTIME(n.created) `post_date`,
 r.body `post_content`,
 n.title `post_title`,
 r.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 stratics.drupal_node n
INNER JOIN stratics.drupal_node_revisions r
LEFT OUTER JOIN stratics.drupal_url_alias a
 ON a.src = CONCAT('node/', n.nid)
WHERE n.type IN ('post', 'page', 'story')

# post -> category relationships
INSERT IGNORE INTO straticswp.wp_term_relationships (object_id, term_taxonomy_id)
SELECT nid, tid FROM stratics.drupal_term_node;

# category count updating
UPDATE straticswp.wp_term_taxonomy tt
SET `count` = (
 SELECT COUNT(tr.object_id)
 FROM straticswp.wp_term_relationships tr
 WHERE tr.term_taxonomy_id = tt.term_taxonomy_id

# comments; keeping unapproved comments hidden
INSERT IGNORE INTO straticswp.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 stratics.drupal_comments;

# update comments count on wp_posts table
UPDATE straticswp.wp_posts SET comment_count = (SELECT COUNT(comment_post_id) FROM straticswp.wp_comments WHERE = straticswp.wp_comments.comment_post_id);

# fix breaks in post content
UPDATE straticswp.wp_posts SET post_content = REPLACE(post_content, '', '');
# fix images in post content
UPDATE straticswp.wp_posts SET post_content = REPLACE(post_content, '"/files/', '"/wp-content/uploads/');

UPDATE straticswp.wp_posts SET post_type='post' WHERE post_type='story';

UPDATE straticswp.wp_posts SET post_name=REPLACE(post_name,'stories/','');