A Step By Step Guide to Moving Content From One WordPress Site to Another
A Step By Step Guide to Moving Content From One WordPress Site to Another
Moving your WordPress site to another location can be a stressful and fiddly experience, not helped by the fact you can’t just simply move your files and database. No, that’s just not how WordPress works.
Fortunately, WordPress has a handy “Import” and “Export” tool built in. But unfortunately, it’ll only suit some basic requirements and you need to improvise a little to achieve other effects.
In this article, I’ll show you step-by-step how to migrate your WordPress installation’s content to a new place.
Let’s get cracking!
Before We Start: Back Up Your Website
Some WordPress installations or server setups may present you with unique challenges on migrating content. Although this article will deal with an additional unique eventuality (namely that you only want to transfer a part of your WordPress installation’s content), there’s no guarantee that the steps detailed here will unfailingly work for every setup.
It goes without saying that you’re solely responsible for your site, even when following this guide to the letter; there’s some database work involved depending on what you want to do, and if you accidentally delete a huge chunk of your site, that’s down to you. Basically, be careful with this!
For the purposes of this post, I’ve created two separate localhost installations of WordPress to provide you with pictures of each step. You might like to try moving your content to a test site to check it works.
To that end, I’d recommend making a backup of your entire site at this point. Of course, you do that regularly, don’t you? (If not, you definitely should be. Get to it.)
If you want to do this manually, remember to include both your database and site files (primarily because this includes your website’s Uploads folder).
Backing Up Files
You can create and download a ZIP of your site files via FTP. How to do this varies per FTP client but is generally fairly obvious. Make sure you download and securely store your backup compressed file – just as with any backup.
Backing Up Your Database
Login to your phpMyAdmin account and select the database in which WordPress is installed.
Select Export from the top menu. For most people, “Quick” options will be adequate. However, if you have tables other than the WordPress installation you want to back up in the same database, click Custom to select the tables you want to back up; all other options should remain untouched. Finally, click Go to download your database backup file (.sql format).
Hopefully, those backups won’t be needed, but it’s always advisable before embarking upon such work. If the site to which you’re migrating content already has content, make sure you back up that one too.
With precautions out of the way, let’s get to work!
Changing Your WordPress Installation’s URL? Transferring a Whole Site
If you’re just looking to change your website to a new URL or otherwise want to transfer absolutely everything from one installation to another, the good news is that you’ve picked the easy option. WordPress’s own import and export tools will work perfectly for you so no need to do anything too complicated under the hood.
Here’s how to transfer all your WordPress content – pages, images and files, posts and everything else – to a new installation.
Incidentally, it is probably easiest to create a new installation on your new server (or even the new location within a server) and import/export than to change your files’ configurations. However, if you’d rather do it that way, the WordPress Codex can advise. Your installation should be up-to-date with the latest WordPress version so it won’t be a problem, but if it’s not, upgrade your old installation first. If you really can’t update for some reason – such as keeping a plugin that doesn’t work with new versions – your new installation can be an old version. This is far from recommended because many old versions of WordPress have critical security flaws.
1. Export From Your Old Installation
Go to your WordPress dashboard and select the Export item from the Tools section.
Because you’re exporting everything, it’s easy: keep the All content option selected and hit Download Export File.
An XML file will be created. Keep it in a safe place and go across to the installation to which you’re migrating.
2. Install the Importer
On the new WordPress installation, go once again to Tools, but this time select Import.
You will be shown a list of importers, from which you should select the WordPress option.
Click Install Now and wait for the importer plugin to download and install.
If it all works, you can click Activate Plugin & Run Importer on the next screen.
At this point, you’re all ready to import and the XML file you generated earlier comes into play.
3. Upload Your Content
Click Choose File on the screen that follows and select the XML file you created on the old site.
Next, click Upload file and import.
4. Assign the Content
You’ll be given an option to assign content to existing users on the new site (if you have an account on both, you can assign your old posts to your new account), or create new users either with their old usernames or with a new one you select. This ensures all the content is attributed to an author account that exists on the new site.
If you have any images or files to move to the new site, make absolutely sure that you tick Download and import file attachments – it’s not selected by default.
Hit the Submit button and you’re done! The page may take a little longer than usual to load because it’s creating all the new rows on the database, but it will get through it. Just wait patiently for it to be processed and all of your content should be imported onto the new site ready for its life there.
Partial Content Movement
So that’s the easy bit out of the way. However, if you’re looking to export only some of your content, I’m afraid to say that WordPress’s tools probably won’t cater for your needs on their own.
Selecting All content is the only way to export your attachments (files that appear under the Media section). Therefore, if you want to transfer specific parts of the content and your images, you’ll either need to move everything across then delete it (time consuming for larger sites) or poke around in your files and database – which I shall show you how to do now.
The exporting and changing SQL that I’m about to show you will be demonstrated for moving attachments, but you can also use a similar methodology to transfer the whole database across. This is useful if you want to transfer everything but your XML file is too large to upload through the importer.
1. Select the Content You Want to Export
Venture once more to the Tools > Export screen to begin with.
Once you’ve selected which content you’d like to export, click Download Export File as before. If there are multiple selections you’d like to make (eg. two authors’ posts in a date range, or someone’s posts and all pages), it’s entirely possible to go back and create multiple export files for each selection.
1.6 million WordPress Superheroes read and trust our blog. Join them and get daily posts delivered to your inbox - free!
2. Import as Before
After you have all the WXR XML files you want, go to the new site and install the WordPress Importer as previously shown. You can upload your files (one at a time) as before and they’ll install the specific posts/pages/other content onto the site.
However, this is not the end, because you’ll notice that you still don’t have any attachments (eg. uploaded images) on your installation quite yet.
3. Duplicate Media Files
Go to your old installation’s FTP client and find the
/wp-content/uploads/ folder. I’m using Windows 10’s File Explorer as my FTP client, but most should be able to compress files and download them.
Download the .ZIP file you generate and upload it to your new site’s FTP (or cut and paste it if you can access both sites through your FTP client).
You can then extract all the files from the compressed folder into the Uploads directory.
Unfortunately, that’s not the end of it; while your files are in the right place, your WordPress installation won’t know about them because the attachment details haven’t yet been copied across from the database.
4. Export Attachment Posts
Head over to your old site’s phpMyAdmin database and find the
wp_posts table (replace
wp_ with your prefix as necessary).
At this point, you need to find the attachment posts (those are the media posts) so paste in the following SQL (changing the table name to have the right prefix if necessary) and hit Go.
SELECT * FROM `wp_posts` WHERE `post_type` = "attachment"
Scroll to the bottom of the query results and check Show all so all attachment posts are showing. Once all rows are displayed, choose Check All then click Export.
At this point, things get a bit more complicated, but stay with me and follow the steps carefully and you should be fine.
- Choose Custom to show all possible settings.
- Scroll down to the Format-specific Options section.
- Choose data.
- Leave everything else as it is and click Go.
5. Edit Your SQL
This step is necessary if your new installation has a different database prefix to the one from which you’ve just downloaded your SQL export file.
Edit the .sql file using a text editor such as Notepad++, finding and replacing the old prefix with the new prefix.
If your prefixes are the same (eg. both tables are
wp_posts), that’s fine and you can ignore this step.
6. Import Attachment Posts
Go to your new database and find
wp_posts (or equivalent); click Import.
Click Choose File – make sure you click, don’t drag it in, as this means it won’t be uploaded in the right place – and select the exported SQL file.
Leave all other options as they are and execute the query by hitting Go. You’ll see a success message once it’s finished and all your attachments will now be visible under Media – although there’s a further step before your images will start showing up properly.
7. Export Post Meta
Similar to the previous database work, this time find your old installation’s
wp_postmeta table and select the Export tab.
Select Custom settings again and choose data rather than structure and data, just as before.
This time, also locate the Data Creation Options heading and select REPLACE as the function to use when dumping data.
Once again, click Go to create and download your SQL file.
8. Edit Your SQL
Again, you need to change the prefixes in your SQL file if the new database prefix will be different. You should also find all references to your old URL and replace them with the new one.
9. Import Post Meta
Go to your new
wp_postmeta (or other applicable prefix) table and, exactly as before, import your edited SQL file into the new installation.
Your media library is now complete once more, ready to fit back into your transferred content (finally).
If you’ve got through all that, well done – it’s a bit of a roundabout method just to transfer some images across with specific posts.
Of course, there are still catches with this: if you only want to migrate some of the images, you need to go through and pick out the folders (hopefully you want them by date or it would take forever) more carefully when uploading. You could also run into trouble with duplicate primary keys transferring
wp_posts if you already had posts on the new installation.
Clearly, to make the Import/Export process more intuitive – rather than requiring such creative thinking with the databases behind the CMS – some work will need to be completed for a future WordPress release. While we wait, however, if you do need to move some of your content, this should work for you – it’s well worth the time!
If you’ve got any more ideas and methods for moving across parts of a WordPress installation with all the content in tow, we’d love you to share it with us in the comments. Likewise, let us know if you’re having any issues with these methods and we can try to give you a hand.