Quantcast
Channel: BloggingPro
Viewing all articles
Browse latest Browse all 30

Tutorial: How To Merge 2 WordPress Blogs

$
0
0

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:

[sql]UPDATE tablename SET tablefield = replace(tablefield,’findstring’,’replacestring’);[/sql]

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

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

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 WordPress hosting providers 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:

[source]define(‘DB_NAME’, ”); // The name of the database
define(‘DB_USER’, ”); // Your MySQL username
define(‘DB_PASSWORD’, ”); // …and password[/source]

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:

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

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.


Viewing all articles
Browse latest Browse all 30

Trending Articles