How to Migrate Just the Content and Media You Specify to a New Site - ManageWP

How to Migrate Just the Content and Media You Specify to a New Site

Going from old WordPress site to new WordPress site

WordPress has a handy Export / Import tool to move content from one site to another, but it has some unintuitive quirks you should  know about if you’re planning on using it.

One of the common “gotchas” is that exporting just posts or pages doesn’t also include their media attachments — like images and PDFs — even if you check the appropriate box during the import process. The import process works fine; it’s the exporting that can be tricky and is all-important.

The following instructions will point out all the gotchas and provide the exact instructions you need to move just the content you want to a new site, with zero downtime and including the attachments.

Getting Started

First of all, it helps to realize that WordPress’ export function doesn’t include the “attachment” post type unless you select the “All content” export option. The problem is that if you don’t want to import all your pages, custom post types (CPTs), nav menus, etc. — just some of them — you lose your attachments. You could move the files via FTP, but then you’ll have a bunch of files on your new site’s server that aren’t attached to posts in the database, and you’ll have files on your server that aren’t being used because they only apply to pages and posts that you didn’t import to the new site.

In order to get the old site’s attachments to import to the database and attach to their imported posts, pages, and CPTs, you need to have both the attachment post_type and the post post_type items in the same import file.

To be clear, it will NOT work to import posts first and then attachments in two separate files. It ONLY works as desired if imported at the same time within the same import file.

How to Selectively Export Posts PLUS Attachments

I needed to move some of my posts and attachments from cliffpaulick.com to endzonerealty.com. I started a tech-savvy Tulsa real estate brokerage and previously used cliffpaulick.com as my REALTOR® website. Now, I want my endzonerealty.com site to look like it’s had quite a few posts over the past few years, and I want to use cliffpaulick.com as more of an About Me (the human) site, not just a “Cliff the REALTOR®” sort of site.

For the purposes of exporting and importing, let’s call cliffpaulick.com the “old site” and endzonerealty.com the “new site”, even though the old site won’t be gone after we’re done.

If I were moving all of the domain’s content, I’d just do a full export/import and redirect all of the old domain’s links to the new domain’s links via the .htaccess file or some other programmatic method. However, I need a more granular solution. The old site’s attachments and selected posts need to be in the same import file, as stated above, but I only want some, not all, of the old site’s posts.

Here’s what we need to do:

I’m not a PHP master, so maybe there’s a better way, via the export_wp function, to export just the ‘post’ and ‘attachment’ post types into a single .xml file, but here are two ways it can be done manually.

Prepare for Exporting

Before clicking the Export button, we want to make sure all the old site’s posts are ready to go. Each site is different, so consider these items for your old site:

Export/Import Option 1: Export Selected Posts, Export All Attachments, Combine into One File, Import

This method is what I chose to do because it makes for a cleaner (but longer) export process on the old site but a cleaner (and shorter) import and deleting process on the new site. However, there’s a bit more human error factor here so don’t rush through the process, especially when merging the export files into a single import file.

  1. Perform a full (files + database) backup of your old site.
  2. Perform a full backup of your new site.
  3. Clean up your old site’s posts, as described in the previous section.
  4. Perform a full backup of your old site again (or just a database backup if you prefer).
  5. Download and activate rcain’s export attachments only plugin modification so you don’t have to edit WordPress core files to get the Media option to show up (since Media is a _builtin post type).
  6. In wp-admin, go to Tools -> Advanced Export and generate the export file, selecting your desired category for the Restrict Category option. FYI: Only categories with posts in them will show up in the Categories drop-down box.
  7. Again in wp-admin -> Tools -> Advanced Export, now generate the export file for attachments.

    WordPress Advanced Export - attachment post_type
    WordPress Advanced Export – attachment post_type
  8. Open the posts export file in a text editor on your computer.
  9. Perform a Search and Replace to replace all references to the old site to instead reference the new site. For example, replace www.cliffpaulick.com with endzonerealty.com, and save as a different filename (just to be safe).
  10. Close the original posts export and open the attachments export so that you have both files open.
  11. Near the top, find the first <item> in the post export and copy through to the last </item> at the bottom of the file.Last item in the WXR file
  12. In the attachments export file, find the last </item> and paste from the posts export and save to a new file (just to be safe).
    This is your new import file.
  13. In your new site’s WordPress Dashboard, go to Tools -> Import and select WordPress. If prompted, download and activate the importer plugin. (FYI: I tried rcain’s version (linked above) but didn’t experience any differences, maybe because my attachments didn’t have any relative file paths.)
  14. At Tools -> Import -> WordPress, upload the file, continue, choose the user to import as, check the box to “Download and import file attachments”, continue, and wait a few minutes. (FYI: If on a multisite setup, I believe the site quota is ignored and more than 100% is allowed to be imported. Regardless, you might want to edit the site’s quota before running the import, just to be safe.)
  15. Once completed, take note of any files that didn’t import, if any, and try to resolve those issues manually. Likely, it’s a file type/extension restriction on your new site’s settings.
  16. Take a full backup of the new site.
  17. On the new site, go to Media -> Library -> Unattached. Check all (that weren’t previously there; that really do not belong on the new site) and Delete Permanently. This will delete from the database and the server. Basically, we’re deleting all the attachments that imported that weren’t attached to one or more of the category of posts we imported. Make sure to review these before deleting, as some may be in use by your new site (i.e. were there before the import). The new site’s content import has been completed.
  18. On the new site, mass edit the imported posts and remove the “new-site” category.
  19. On the old site, install and activate the Page Links To plugin by Mark Jaquith, which actually changes the post’s permalink to be the redirect location.
  20. On the old site, edit each published post’s Page Links To field to point to the new location (save some time by deleting the drafts, since they got moved over anyway, if you selected to). The WordPress Importer’s default is to assign the posts from the old site to keep their same post_id on the new site, except when that post_id already exists. So, for most posts, you can probably do something like this: redirect cliffpaulick.com’s post_id 58 to http://endzonerealty.com/?p=58 via Page Links To.
  21. After some time, maybe a week, month, year, or longer, you can delete all those posts instead of leaving them published with a Page Links To redirect. Or, if you prefer to setup all the redirects programmatically, you’ll need to account for all the different ways visitors can get to a single post: post ID, current slug, previous slug, trailing slash, non-trailing slash, etc. Doing it manually will allow you to view each post on the new site to make sure the content displays well.
  22. On the new site, you’ll probably want to go through the posts one-by-one, editing/deleting comments, featured images, custom fields, etc.

Export/Import Option 2: Export All, Import All, Delete Unneeded Stuff

This method is much easier to import, but you’ll need to carefully go through your new site’s content and get delete-happy post-import. If you’re moving the large majority of the old site’s content, this is probably the better option.

  1. Follow the backup, cleanup, backup steps above.
  2. In the old site’s WordPress Dashboard, go to Tools -> Export and leave the default “All content” selected and download the export file.
  3. Follow steps 13-16, above, to import.
  4. So now you’ve imported your ENTIRE old site into the new site. You’ll need to go through your new site’s entire content to figure out what to delete (i.e. what you didn’t want to import). For example, if you imported 10 tags and 12 posts that you didn’t want to import, find them and delete them. Because each site is different and have different post types, you’ll probably just want two browser windows open and go through the wp-admin area of the old and new, comparing and deleting as you go.
  5. Once your new site has the content you want it to have — and doesn’t have the content you don’t want it to have — you’ll want to follow step 17, above, to delete the attachments unused by the new site.
  6. Then follow the rest of the steps above, steps 18-22.

Tips and Tricks

In addition to the tips included at the start of this post (in the Prepare for Exporting section), following are some more bits of information you might benefit from in your migration, since every job’s different.

Can I Just Make a Full Copy (i.e. Clone) of an Old Site to Create My New Site?

Yes! With ManageWP’s service, you can do just that.

Head over to the ManageWP User Guide page how to clone a WordPress site to see a video of how easy this is to do. You could call it Option 3. It’s the most comprehensive way to nearly duplicate an entire site, but you’re going to do some additional deleting on the new site.

Tuff Stuff

If that process doesn’t tire you out, nothing will. To celebrate your successful “migration” and help put a smile on your face, get inspired by this flying goose!

WordPress Migration Complete
Celebrate your “migration”

Share Your Experiences

Hopefully this was just what some of you needed.

Please share your experiences and tips in the comments below.

Images courtesy of Todd Slagter and Steve Jurvetson

Clifford Paulick

Clifford Paulick is @TourKick, doing cool things with WordPress, photography, and videography. He provides web and technology consulting services at TourKick.com and is a Tulsa Realtor.

14 Comments

  1. zeeshan

    Hi thanks for great article.I used above method my contents exported successfully but its not showing images and feature images.NOw what should i do.

    Regards

  2. Faizan

    A very Good article indeed. I want to transfer my HD Wallpapers 3d website to another domain with all images. Can you describe the easy steps so that my content get indexed on google. Thanks.

  3. Cristian Sanchez

    Great article, I just have a question? Why I can not see the attachments option on Restrict Content select? do you have any idea?

    Thank you!

  4. Anthony

    very well written and easy to understand.
    Lucky to find this before screwing things up with the migration

  5. John

    Does this migration approach support serialized string replacement? If not, could there be problems as explained here: http://interconnectit.com/products/search-and-replace-for-wordpress-databases/

    Thanks,

    1. Clifford Paulick

      WordPress’ export/import is via XML. It’s not a full database “copy/paste”. The script from InterconnectIT isn’t needed, otherwise I would have added it. Let me know if you have any issues. :-)

    2. John

      It worked! Thanks for the resource. I wish there were better migration tools built into WP.

  6. Wil

    Very interesting, but rcain’s modification doesn’t work for me. If I take the 2.8.3 version (or the new 2.9 version) of the advanced export plugin and modify it, I don’t get an XML file. WordPress outputs a page of text with none of the XML formatting in place.

    Without that step, I’m not sure how I could complete this process. Any tips would be appreciated. Otherwise, thanks for the walkthrough.

    1. Wil

      I should add that I’m using WP 3.5.1

    2. Clifford Paulick

      I’m not sure what I can say without getting in there and digging around so I’ll suggest posting your question to http://wpquestions.com/ or http://wordpress.stackexchange.com/ or somewhere like that. Hopefully that helps.

  7. Kassandra

    Excellent and thorough walk through. Worked fantastic. Thanks for writing this!

    1. Clifford Paulick

      Very glad it worked well for you! :-)

    2. Clifford Paulick

      So glad it worked for you!

  8. Imtiaz Ali

    the best article with a quality content. keep it up dear

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Over 17,000 WordPress professionals are already using ManageWP

Add as many websites as you want for free, no credit card required. Sign up and start saving time!

Have questions? Get in touch!

Over 17,000 WordPress professionals are already using ManageWP

Add as many websites as you want for free, no credit card required. Sign up and start saving time!

Have questions? Get in touch!

Over 17,000 WordPress professionals are already using ManageWP

Add as many websites as you want for free, no credit card required. Sign up and start saving time!

Have questions? Get in touch!

Over 17,000 WordPress professionals are already using ManageWP

Add as many websites as you want for free, no credit card required. Sign up and start saving time!

Have questions? Get in touch!