This Is How To Migrate From Drupal To Wordpress

Posted: Apr 8 2016, 5:23am CDT | by , Updated: Apr 9 2016, 7:19am CDT, in News | Technology News

This is How to Migrate from Drupal to Wordpress

Inside the Geek Mind. How I migrated a Drupal 6 site with over 20,000 articles to Wordpress.

I started out with Php-Nuke as my first CMS over 14 years ago. Seven years later I migrated to Drupal and invested heavily ever since in custom development for this site and others in my company's portfolio.

Once you invested into something for years with money and time, it becomes very hard to change. I came though to the conclusion that for our smaller sites I needed a solution that has much lower cost of ownership. I decided to leave behind all the custom code that we had developed over the past years on Drupal and move to off-the-shelf solutions based on Wordpress.

I am not ready to take that jump for our main site yet, but for our niche news sites this is looks great so far. The Wordpress platform offers a tremendous amount of themes and plugins and a great support community. I will write another post in this "Inside the Geek Mind series" about my experience setting up a complete news site on Wordpress.

Here I want to tell you how I migrated over 20,000 articles from a Drupal site to a new Wordpress site. I have just succeeded doing this and it is still fresh in my mind. When I started to look into the migration of our multi-domain Drupal 6 setup, I thought that migration will not be a problem. There have been for sure many webmaster who have done that before me and there will be good plugins and best practices.

I actually thought I hire someone on Upwork to do it for me for a small money. After two consultants failed to accomplish the migration trying several plugins, I decided to look into it myself after an offer from a professional migration company was just way to expensive.

It took me two days to come up with a migration process that worked. Wordpress's rigid permalinks structure has eaten up the most time, but more about that later. After the consultants I hired failed using Drupal to Wordpress migration plugins, I decided to skip these and go for an xml export and xml import based solution.

How to export Stories from Drupal to XML

The module to use is "Views data export" ( I tried to get the module "Node Export" to work, but failed. With "Views data export" I built a view with the data fields I needed from the story nodes. Just follow the instructions in this example. I found it straight forward to adopt it to my needs.

Important is to export the node id and path along with the story content fields. Below is an example of the resulting xml file that shows the fields I exported.

Drupal XML Export

How to import stories from XML to Wordpress

Now with the xml file in hand containing over 20,000 stories, I needed to find a way to import it into Wordpress. My first plugin pick turned out gold. The WP All Import plugin by Solfyy works great and is incredibly easy to use. There is a free version, but I needed to use premium features such as custom fields to solve the little details that are important. The WP All Import Pro version is $99 - a well worth investment.

WP All Import has a drag-and-drop user interface. In the import wizard I just dragged the tags from the xml file into the matching fields on the page including title, body, creation time, author name and path. The Nid I added as a custom field.

My goal was to migrate all stories maintaining the url structure, to make sure I do not break any external links. This is important for carrying over the search ranking profile. As mentioned above, to figure out how to make this work with Wordpress's permalinks structure was the most time consuming. The main obstacle was that the Drupal urls had slashes in the slug aka page url. This a complete no-go with Wordpress. Slashes are reserved for the Permalinks structure.

The links in Drupal though look like /2016/02/the-title. After endless attempts of rewrites, adding filters I had an under the shower moment. I recreated the Drupal url format as Customer Permalink: /%year%/%monthnum%/%post_id%/%postname%.

Now I just had to replace the Wordpress Post ID with the Node ID (Nid) from Drupal and I get the exact same Url for the imported stories on Wordpress. To do that I wrote a simple php script with SQL calls to replace the Post ID with the Drupal Node ID. See the code below.


$res = $wpdb->get_results("SELECT post_id, meta_value FROM 
$wpdb->postmeta WHERE meta_key = 'drupal'");

foreach ($res as $row){
$drupal = $row->meta_value;

$wpdb->query("UPDATE $wpdb->posts SET ID =". $drupal." 
WHERE ID = $row->post_id");

$wpdb->query("UPDATE $wpdb->postmeta SET post_id =". $drupal." 
WHERE post_id = $row->post_id");


A small detail to resolve before this works was to remove the year, month and node id from the Path string in the XML file. The WP All Import offers for this problem a feature called Custom PHP functions. In the Wordpress Theme functions.php file I added this short code.

function drupalpath($x) {
    // do something to $x
   $l = explode ("/",$x);
$x = $l[4];
return $x;

Inside the value field of the Nid custom field in WP All Import I call that function with:


As a result the imported stories have as slug only postname. The last thing that remained to do was to make sure that new Wordpress posts are not using an ID from the imported Drupal ids. The solution for this is to set an higher post ID to for Wordpress to start with. That global post ID is a bit hidden. It is the auto increment value in the posts table in the Wordpress mysql database.

The AUTO_INCREMENT value can be set in the Operations tab of the posts table in PHPmyAdmin.

One more thing to take care of before importing is to create all author accounts. WP All Import can match the Author name by username or email. I just used the username, which worked right away. This way authorship is maintained after the migration.

To import about 23,000 stories using WP All Import takes 40 minute on a Siteground hosted Wordpress site. My needs for the Drupal to Wordpress migration have been minimal, but I believe this method also works for more complicated migrations with more node fields and higher numbers of posts.

If you have questions about this solution feel free to post in the comments below.

This story may contain affiliate links.


Find rare products online! Get the free Tracker App now.

Download the free Tracker app now to get in-stock alerts on Pomsies, Oculus Go, SNES Classic and more.

Latest News


The Author

<a href="/latest_stories/all/all/2" rel="author">Luigi Lugmayr</a>
Manfred "Luigi" Lugmayr () is the founding Chief Editor of I4U News and brings over 25 years experience in the technology field to the ever evolving and exciting world of gadgets, tech and online shopping. He started I4U News back in 2000 and evolved it into vibrant technology news and tech and toy shopping hub.
Luigi can be contacted directly at ml[@]




comments powered by Disqus