Backend / DevOps / Architect
Brit by birth,
located worldwide

All content © Alex Shepherd 2008-2024
unless otherwise noted

Migrating Drupal 7 to Wordpress 3.

Published
1 min read
image
Image Credit: Unknown (if this is your work, reach out to me and I'll credit you!)

Hi folks,

I recently got asked to convert a Drupal 7 site to Wordpress 3. I thought this should be a fairly easy process, but boy was I wrong. The only way to do it is to go messing around with the database, so here's Uncle n00b to guide you through the fairly horrible process, as there are very few sites with so much as *any* information on how to do so.

This article is based on information found here and here.

Step 1: Convert Drupal taxonomy to Wordpress terms.

We use REPLACE to avoid duplicating terms.

REPLACE INTO wordpress.wp_terms
(term_id, `name`, slug, term_group)
SELECT DISTINCT d.tid, d.name, REPLACE(LOWER(d.name), ' ', '_'), 0
FROM drupal.taxonomy_term_data d
INNER JOIN drupal.taxonomy_term_hierarchy h USING(tid)
WHERE 1;
INSERT INTO wordpress.wp_term_taxonomy
(term_id, taxonomy, description, parent)
SELECT DISTINCT
d.tid `term_id`,
‘post_tag’ `taxonomy`,
d.description `description`,
h.parent `parent`
FROM drupal.taxonomy_term_data d
INNER JOIN drupal.taxonomy_term_hierarchy h
USING(tid)
WHERE 1;

This code is perhaps not quite complete, as we fill 0 into term_group. I, however, only required one level of taxonomy, so it wasn't really a problem.

Step 2:

Now you need to insert the posts. This is a 3 step process.

INSERT INTO wordpress.wp_term_taxonomy
(term_id, taxonomy, description, parent)
SELECT DISTINCT
d.tid `term_id`,
‘post_tag’ `taxonomy`,
d.description `description`,
h.parent `parent`
FROM drupal.taxonomy_term_data d;

INSERT INTO wordpress.wp_posts(id,post_author,post_date,post_content,post_title,post_excerpt,post_name,post_modified,post_type,`post_status`)
SELECT DISTINCT n.nid `id`, n.uid `post_author`, FROM_UNIXTIME(n.created) `post_date`, r.body_value `post_content`, n.title `post_title`, r.body_summary `post_excerpt`, (LOWER(REPLACE(n.title, ' ', '-'))) `post_name`, FROM_UNIXTIME(n.changed) `post_modified`, n.type `post_type`, IF(n.status = 1, 'publish', 'private') `post_status`
FROM drupal.node n, drupal.field_data_body r WHERE n.vid = r.entity_idsite=refman-%35%31&q=INNER">INNER JOIN drupal.taxonomy_term_hierarchy h
USING(tid)
WHERE 1;

Now fix the post types:

UPDATE wordpress.wp_posts
SET post_type = 'post'
WHERE post_type IN ('article');

You want to set post_type to 'post' for all content types you want to appear as Wordpress posts.

The next step is to go through post_name manually and make sure that each one is a decent representative browser-compatible and SEO'd title slug.

Step 3: Clean Up

The source links I've left you with at the top tell you how to convert the comments if you need to, and you also now want to go through the Wordpress site with a fine-toothed comb, making sure that any anomalies are cleaned up manually.

As always, any questions can be directed to the comments or the contact form! Disqus doesn't appear to be working for HTTP and HTTPS simultaneously, so you'll have to leave comments via HTTP for now - sorry folks!

n00b