How to migrate content from Drupal 7 to WordPress 4?

Sometimes you realize the technology you used for your application or website is actually more complex than needed (do you remember what this acronym KISS means?) or maybe you just want to get on the same wavelength and try this famous CMS (WordPress) everybody is talking about. In either case, you cannot just dismiss your thousands of posts you have been publishing throughout time in your old Drupal site, so what can you do?

The obvious solution here is migrating your articles and turning them into WordPress pages and posts, but this sounds like a daunting never-ending task (and it is, if you do it manually). Fortunately, in the IT era, a lot of things can be automatized and moving content from one CMS to another is no exception. Here I’m going to run through the main steps to gradually take your information from your steroid-inflated Drupal installation to a skinny (but agile) WordPress one.

1- Cleaning tables:

I’m assuming you already have a WordPress instance set up, so the first thing to do is preparing your tables for the migration process by using a MySQL client (WARNING: this will delete any existing post, category, tag or comment):

TRUNCATE TABLE wp_comments;
TRUNCATE TABLE wp_links;
TRUNCATE TABLE wp_postmeta;
TRUNCATE TABLE wp_posts;
TRUNCATE TABLE wp_term_relationships;
TRUNCATE TABLE wp_term_taxonomy;
TRUNCATE TABLE wp_terms;

2- Cleaning user table:

You need to remove existing users in order to prevent them from causing a conflict with the ones imported from Drupal:

DELETE FROM wp_users WHERE ID > 1;
DELETE FROM wp_usermeta WHERE user_id > 1;

3- Migrating terms:

REPLACE INTO wp_terms
(term_id, `name`, slug, term_group)
SELECT DISTINCT
d.tid, d.name, REPLACE(LOWER(d.name), ' ', '_'), 0
FROM taxonomy_term_data d
INNER JOIN taxonomy_term_hierarchy h
USING(tid)
INNER JOIN taxonomy_index n
USING(tid);

4- Classifying terms into tags and categories:

INSERT INTO wp_term_taxonomy
(term_taxonomy_id, term_id, taxonomy, description, parent)
SELECT DISTINCT
d.tid `term_taxonomy_id`,
d.tid `term_id`,
IF (format = 'plain_text', 'category', 'post_tag') `taxonomy`,
d.description `description`,
h.parent `parent`
FROM taxonomy_term_data d
INNER JOIN taxonomy_term_hierarchy h
USING(tid)
INNER JOIN taxonomy_index n
USING(tid);

5- Migrating pages and articles and turn them into WordPress pages and posts, respectively:

INSERT INTO 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`,
f.body_value `post_content`,
n.title `post_title`,
f.body_summary `post_excerpt`,
REPLACE(a.alias, '/', '-') `post_name`,
FROM_UNIXTIME(n.changed) `post_modified`,
IF(n.type = 'page', 'page', 'post') `post_type`,
IF(n.status = 1, 'publish', 'private') `post_status`
FROM node n
INNER JOIN node_revision r
USING(vid)
LEFT OUTER JOIN url_alias a
ON a.source = CONCAT('node/', n.nid),
field_data_body f
WHERE r.vid = f.revision_id AND
n.type IN ('page', 'article');

6- Linking posts to terms:

INSERT INTO wp_term_relationships (object_id, term_taxonomy_id)
SELECT DISTINCT nid, tid FROM taxonomy_index;

7- Updating taxonomy counts:

UPDATE wp_term_taxonomy tt
SET `count` = (
SELECT COUNT(tr.object_id)
FROM agdevwp_term_relationships tr
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id);

8- Migrating users:

INSERT IGNORE INTO wp_users
(ID, user_login, user_pass, user_nicename, user_email,
user_registered, user_activation_key, user_status, display_name)
SELECT DISTINCT
u.uid, u.mail, NULL, u.name, u.mail,
FROM_UNIXTIME(created), '', 0, u.name
FROM users u
INNER JOIN users_roles r
USING (uid);

9- Migrating media:

Finally, you can use this plugin “Add From Server” in order to quickly move your old media to the WordPress library

 

 

 


Do you need some help?

Let's get started. Tell us a little about yourself and your organization
and we can start a conversation about your needs and our capabilities.

Related Posts