Let’s say you have a WordPress site that has a bloated database and you want a fresh start. In addition, let’s say that you’ve installed some plugins that leave lots of entries in the WordPress database (Yet Another Related Post, for example) and you want to swap out your old plugins for some new plugins in your fresh installation. Using the built-in WordPress Import function is a simple way to hit the reset button on your blog.
Delete Your Blog, then Re-Import It
Let’s say you have a WordPress site that’s slow and you know needs some spring cleaning in its database to speed it up. You could try to keep your WordPress site the way it is, deleting the outdated plugins and then delete the database entries you no longer need using PHPMyAdmin. But it’s always a risky propositon editing your database, and there are likely thousands of records you’re going to need to delete.
The easiest way to start over with your WordPress blog is to import just the posts + pages from your WordPress site along with the associated images. To do this, we can use the WordPress Import function. One problem with the Worpress Import tool is that it can be a bit “unpredictable” like skipping certain images when you run an import. We’ll import our content without explicit image import, but don’t worry, we’ll use an alternate way to get images into our new site.
- Generate the export file:
- Edit your export file to remove the database id’s of your photos. The photos linked on your old site will have numbers attached to them that will no longer be relevant after the move to a new database. So you’ll get image options that look like img class=”size-full wp-image-152. Thee “wp-image-152” image number isn’t technically necessary, especially for imported images. You can do a search/ replace in your WP import file to delete those entries. In a text editor, the following search finds all instances of this string which you can then delete at once:
- Drag all your images into your Media Library (in your Dashboard, select Media > Library > “Add New”). If you previously used the option to organize your photos into month/year folders, then you’ll need to search and replace again in your text editor:
You can match the above pattern for all your 2011 uploads folders, which get replaced with simply “/uploads” if you unchecked “Organize my uploads into month- and year-based folders” in your Settings > Media. If not, then you’ll replace it with “/uploads/YEAR/MO” for the current year and month.
- Start the import from the Tools > Import menu option in your WordPress dashboard. Leave “import images” unchecked. The image URLs will still be in your posts, and when you upload your photos to your Uploads folder back into your new install (through the WordPress dashboard of course), they will show up in your posts.
Restoring Your Old Site Using an Intermediary Site
Some of the difficulties of adding images through the WordPress import could be because the “old” site is unreachable (either because you moved hosting, took the site down and/or changed the DNS). Because your old domain isn’t accessible anymore, the xml file for the import wants to download the images from your old domain but can’t because the DNS does already point to the new host, where the upload folders don’t exist.
If you are doing a new install of your domain on the same server to replace the old one, then it’s more likely the case that the upload folders will be deleted and the import can’t download the images anymore.
To work around this issues, we can use an intermediary domain (like a subdomain) to hold our site during the transiton:
- Use BackupBuddy to clone your old site to a subdomain.
- Proceed to export your site contents from this subdomain site.
- When you import to the new site, allow it to import images. Because the site is still going strong on the subdomain, the image import will succeed onto your new site.