Performancing Metrics

Tutorial: How To Merge 2 WordPress Blogs

Repost This

For a project I am involved with we recently considered merging 2 rather large WordPress blogs. These were 2 blogs with several thousands entries and posts and at least 20 authors have written on those blogs over the years. The combined blog would have more than 10,000 entries and more than 40,000 comments.

In this post I am going to walk you trough the whole process, because it is simpler than it sounds and should not scare anyone away. Depending on how ‘hardcore’ you, the merger could be done in some hours only. Yes, some hours only.

Getting Started

Although this tutorial is aimed at both ‘beginners’ and ‘pros’, I assume that you have a certain basic knowledge, understanding from WordPress and setup already:

  • You know how to backup a database;
  • You know how to FTP;
  • You have a localhost setup;
  • You have a basic understanding of WordPress database tables, ie. when I mention wp_options, you know that this is a database table and you know how to ‘find’ this table;
  • You know how to make changes to the database

The walkthrough is also based on both blogs running a similar permalink structure and using the same plugins.

We will use following terms in this tutorial:

  • Blog 1: Target blog[yoururl], this will be the ‘merged blog’
  • Blog 2: Old blog[oldurl], the blog we are going to import

Step 1: Define your target blog and set a copy of this blog up locally

Once you have your localhost install up and a local WordPress setup, you have to backup your ‘target blog’ database and files and set the blog up locally. You can use any WordPress database backup plugin, my favourite is Lester Chan’s WordPress Database manager, or backup via phpMyAdmin or Shell.
Import this backup to your local setup. Overwrite the files of your local WordPress setup with the files, themes, plugins and uploads from your web server.

Your blog is now installed locally but if you click on the blog title in your WordPress dashboard, you will be taken to the URL and not to your locally installed blog. Go to Settings > General and change your WordPress URL (if needed also the Blog URL) to your localhost installation.

Step 2: Import the second blog locally

Importing the second blog is really simple actually. You even do not need to backup the database of the second blog. Merging both databases would only create problems and not work because you will have several conflicting IDs: post_id, author_id, category_id and several more. Merging two backup’ed databases will result in ‘FAIL’.

Instead we are going to use the WordPress export function and import this file locally. To export the content of your second blog, go to Tools > Export ([oldurl]/wp-admin/export.php) and download the export file for all authors.

Once you have downloaded this file, you can now import all the content to your locally merged merged blog. Go to Tools > Import on your local setup and choose WordPress in the list. Chose the file you have just downloaded and WordPress will now import all entries, comments, tags, categories and create new authors.

Import all uploaded files from the second blog to your local setup now (normally [blogurl]/wp-content/uploads). While doing this, make sure that folders are merged an not overwritten.

Note: The WordPress importer will import all attachments found in entries, but in our case our setups were rather old and many images were in other folders, many have never been imported as attachment. In a previous optimisation they were all moved to the /wp-content/uploads folder and URLs where changed via a SQL command.

Make sure you don’t have 2 ‘About’ pages and also check if the author profiles. During the import, all entry authors have been created by the importer but their profiles (and password) have not been imported. You will have to complete email-addresses and the profile fields for every ‘newly created’ author.

Your blogs are merged now.

Step 3: Replace the old url in your content with the new URL

Chances your blog has many links to the URL of your old blog are high, especially if you have inserted images in entries. To make sure that these links still work we are going to replace the [oldurl] with the new URL in posts and comments.

Nerds United World Wide will enjoy this and look forward to replace all [oldurl] mentions in the database with an SQL command based on the structure:

UPDATE tablename SET tablefield = replace(tablefield,'findstring','replacestring');

To replace your old URL in entries with the URL of the merged blog you would use following command:

UPDATE wp_posts SET post_content = REPLACE (post_content,'[oldurl]','[blogurl]')

We are keeping this tutorial simple though and will use Frank Bültge’s excellent Search and Replace plugin.

search-and-replace

I combined two steps here already and images will now not be displayed on your local blog. To solve this problem, we now upload all uploads (/wp-content/uploads) to the merged blog, otherwise images will not work.
This also means that internal links will not work locally, or on your test blog, but redirect to the non-existent entry on the merged blog already. Do not worry, I merely combined some steps already to make the whole procedure go faster, bear with me for a second.

Note: Working with a local setup

Actually all these steps could be skipped and we could immediately have worked with an online test blog instead. The reason why I chose for a local setup is following:

  • It’s good practice. Too many users do not test before making changes. Screwing up your local setup will not take your site down and the user won’t notice. Get in the habit of using a local setup to test things.
  • You could also test on a test domain or test sub-domain online, but some hosters have limited upload settings. For large blogs 8MB, an upload limitation used by many hosters, sometimes is not sufficient and an upload can always be interrupted. Chances that a local import will fail are smaller than when uploading large import file.

Step 4: Setting up a ‘merged blog’ on a test domain

The following step is to use a test domain or sub-domain and transfer your local merged WordPress blog to an active online environment.

If you need a small reminder how to setup an online WordPress installation, read this post. If your hoster provides Fantastico installation, you can also opt for this procedure.

Now you have to FTP all files from your local WordPress installation to your online test blog. Overwrite all BUT ONE files on the online WordPress installation: do not overwrite the wp-config.php of the online installation.

The next step will be to import the database from your local installation to your online test site. You can once more use the WP-DB Manager plugin to backup your local WordPress database.
You can now import this database via phpMyAdmin but if you do not have shell access (or the shell scares you), I recommend you to upload this file to your hosting and ask your webhoster to import this database. Going this path avoids that your browser based import might be interrupted during upload and fail. Remember, in my example we are speaking about a big database: more than 10k entries and 40k comments.

Step 5: Test, test, test

Now it is time to extensively test your test setup because in the next stage we are going to switch databases and within seconds we will be live.

Test, test, test. Email your authors, tell them to request a new password via the login page. Tell them to create drafts and ask them to browse your archives and notify you of all errors they find.

If they find a 404, tell them to replace the URL of the 404 with the URL of the test blog. Remember that I told you to replace all URLs already? Yup. If after this they find the entry, move on.

Continue testing until you think everything works.

Step 6: We are switching Live

Now we are going to switch live. This involves 3 steps. First though, I advice you to get a statistics package with live updates so you can see what’s going on on your site. Use our PMetrics, Woopra or Chartbeat. This helps you identify 404s and correct them as you notice traffic to not found pages.

Step 1: Switch databases
Within WP, go to Settings > General and change your WordPress URL (if needed also the Blog URL) to the URL of the merged blog.

Open the wp-config.php of the merged blog and change:

define('DB_NAME', '');    // The name of the database
define('DB_USER', '');     // Your MySQL username
define('DB_PASSWORD', ''); // ...and password

To the settings in the wp-config.php on your test blog.

Double check, triple check, quadruple check this because when you hit ‘Save’ your merged blog will be live and use the database of your test blog! Yes, you can also download the wp-config.php of your test blog and FTP it to the merged blog.

Step 2: Redirect the old blog to the new blog
Your merged blog should now be fully functional and have all entries from both blogs on one install. Now it is time to redirect the old blog to the new, merged blog. We are going to do this with the help of a 301 redirect. This does not only mean that the visitors of your site will be redirected to the new blog but search engines will also update their listings and ‘pass on the juice’. We will use some .htaccess rules for this. Replace the content of your .htaccess on the old blog with this:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com
RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]

Step 7: Relax, this works

Normally you should now be totally wired up and close to being a nervous wreck. Instead… go for a quick frozen one and let your editor deal with the complaints.

Hey, where are you? I said a QUICK one, that shouldn’t take more than 10 minutes!

I now have to tell you that you should be prepared to work hard correcting errors for the next 2 or 3 hours, but I won’t. If you have followed this tutorial, everything should work fine now and if you run in problems on your live setup, you only need to revert two files: the wp-config.php on the merged blog, back to the original database, and the .htaccess on the old blog, back to before the redirect rules. Of course you did make a backup of these, didn’t you?

Now write an entry on the merged blog about the merger and keep an eye on your live stats and the comments on the announcement for the next 2 or 3 hours. If everything is fine, change the Feedburner settings for the old blog to the new one if you use Feedburner.

You can now go and celebrate the operation with a more frozen ones. The next day when you wake up, probably hungover because boy was that a party, check your email, comments and stats and look if any errors have come up. Correct.

Congratulations on the move.

One last, small note

You might have noticed that I said to start your local installation with a database import. You could also have imported ‘an export’ to start the local installation. I opted for a database import because custom fields get lost with the export/import routine from WP. If your theme uses them, you should start with a db import.

Repost This

Categories: WordPress Tutorials
Tags: , ,

This post was written by . You can visit the for a short bio, more posts, and other information about the author.


Comment with Your Facebook Account

Comments

  1. David Krug ) says: 12/17/2009

    Very interesting. I did this in the past with a few blogs. But appreciated the tutorial anywho.

    Reply

    • Franky ) says: 12/18/2009

      David, it’s nice that WP makes things this easy. I have done this more than once on live sites even.

      Reply

  2. miles says: 12/18/2009

    just wanna say merry xmas

    Reply

  3. Ricky ) says: 3/7/2010

    It did work well for me check http://techgenuine.com/2010/03/how-to-share-google-buzz-on-twitter-account/ but my old domain names images are throwing 404 error. In my case my blog is in /blog directory so images are in blog/… directory but in the case of new domain it is redirecting it to root directory http://geniusgeeks.com/wp-content/uploads/2010/01/free-java-mobile-downloader-application.png but this image is alive in http://geniusgeeks.com/blog/wp-content/uploads/2010/01/free-java-mobile-downloader-application.png url.

    How can I solve this?

    Reply

  4. Carol says: 7/16/2010

    Thanks for another fantastic article. I am always looking for original WordPress tutorials to suggest to my own readers. Thanks for creating this post. It’s just what I was trying to find. Truly phenomenal post.

    Reply

  5. Faizan ) says: 9/28/2010

    very nice post and illustration is simple! but what i was looking for didn’t come out. i actually want to create a website with two blog pages. i want to have control over both the pages dynamically. can i do so?

    Reply

  6. MafiaBoy says: 10/12/2010

    Thanks for the nice and detail instructions.

    Reply

  7. Dog Bark Collar says: 10/27/2010

    Hi Franky, thanks for sharing these instructions. This is what I’m looking for.

    Reply

  8. Ash says: 12/12/2010

    Thanks for this well written article!
    Appreciate your efforts in putting this together.

    Reply

  9. Mamie Aslett says: 2/11/2011

    I like this website very much, Its a rattling nice position to read and incur info .

    Reply

  10. Adriana says: 2/25/2012

    thanks for share!

    Reply

  11. Steve ) says: 11/28/2012

    You just made my life a whole lot easier. I was merging a few sites and this made the process pretty straightforward

    Reply

Content


Receive the top stories from BloggingPro and the Splashpress Media network every week, right in your Inbox. Relevant and timely content is yours for FREE!