Menu

WordPress Import Failed? Here’s How to Fix It

Before we start…

If you’re fighting with WordPress, you’re obviously smart and technical. If you have any interest in digital marketing and SEO, you might like my SEO company in Central MA, Mxt Media.

Check us out! I’d really appreciate your feedback. Thanks. Now onto the good stuff:

If your WordPress import failed, here’s the solution.

No wasting time. Let’s get right to it. Follow these steps to import your WordPress XML data even if it’s failed in the past.

1. Export XML data

You probably already did this. If not, go to your old WordPress website. In the WP-Admin area, find the Tools > Export menu item. Hit the blue “Download Export File” button and save the XML file generated.

2. Divide file into small chunks

This part is a pain in the ass. And it requires a working knowledge of XML (or HTML) markup. Open your favorite text editor. I prefer Coda or Sublime Text, but just about any will do. DO NOT USE MS WORD or any other “word processing” application. It must be a basic text editor like Notepad, etc.

The first 20-ish lines are all instructions. They’re not important. However, the <?xml version="1.0" encoding="UTF-8" ?> tag on the top line is very important. Wherever you see the <rss version="2.0"... and the <channel> tags, that’s where the content starts.

Now, here comes the hard part.

3. Make sure chunks are properly formatted

Back to that working knowledge of markup thing. Every chunk has to start and end with the proper tags. Make sure your chunks follow this pattern:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <rss version="2.0"...
  3. <channel>
  4. <wp:wxr_version>1.2</wp:wxr_version>
  5. Your 5,000-ish lines of content, starting with <item> and ending with </item>
  6. </channel>
  7. </rss>

You can have many, many <item>...</item> tags within your 5,000 lines―and in fact, you definitely should. But your content MUST be wrapped within <item>...</item> tags (plus the others described above) or the import will break.

You will have to copy and paste these tags into the top and bottom of each file (or start with one file like this and paste your content into the middle). It’s a pain and it must be done properly. If you have a problem, it’s probably because this step was done wrong.

Here’s an example XML document I’ve edited to match the pattern above. Download and inspect it in your favorite text editor. Make sure yours looks similar in format.

4. Upload chunks individually

Repeat the Tools > Import > WordPress Import process you’re already familiar with. This time, import these smaller files that won’t take forever to parse. Your data should import just fine, albeit in smaller installments.

Drawbacks of this method

My solution isn’t perfect. It has two drawbacks, one bigger than the other: it’s tedious and it might break your data’s relationships.

It’s slow and tedious

It’s a total pain to go through a 100,000-line file and break it into 5,000-line chunks. And, as far as I know, it can’t be automated (at least not by the average WordPress user). But if you’ve got an hour or two and the patience of a saint, the tedium isn’t the end of the world.

It might break your meta data/relationships

This one could be a deal-breaker for some. Here’s the problem: if you have two pages in your site: Page ID #10 and Page ID #20. For whatever reason, you created 20 after 10, but 20 is the parent of 10. Read that carefully: 20, the higher ID and newer page, is actually the parent of 10, the older page. (I know that sounds weird. It doesn’t matter why. Maybe you added a category-level landing page [20] to list all sub-pages [10, 12, 14, etc.] Whatever, just go with me on this.)

Well, if you import a chunk that defines page 10 but cuts off before defining page 20, you’ll be telling WordPress to import/create page 10 and its parent is 20…but you haven’t imported 20 yet. That relationship is invalid. WordPress sees the invalid relationship and just skips right over it. They SHOULD throw an error or at least warn you of the problem, but it’s rare and most people won’t care so they probably just didn’t bother.

Now, when you do get around to importing/creating page 20, that relationship should be restored right? Well, the truth is I don’t know. I think so. But stranger things have happened. And I’ve dealt on more than one occasion with a list of imported pages whose parent/child relationships are all bonkers. So I’m blaming it on this little gem right here.

The real problem/cause

The problem here is not with uploading the XML file. It’s with processing it. Once uploaded, WordPress passes the XML file into a PHP processor script. The processor parses through each line of the XML document and handles the data accordingly. Namely: it inserts records into the database according to the XML doc’s content and meta definitions (author, publish date, status, tags, etc.).

It’s that markup-parse/database-insert process that causes a problem. It just takes too long. 2MB of plain text—like in an XML file—is a TON of text. The server takes forever to process all the data in the 2MB file. And most servers have a timeout limit. They don’t let the process run long enough.

Technically, the failure isn’t WordPress’ fault. It’s the server’s. But of course WordPress’ system files can’t foresee or control that, so they have no way of alerting the user when it happens―there’s no WP error message for that.

So the “2MB is way less than 7MB” is deceiving. The 7MB limit is just for the file upload. It has nothing to do with processing the data contained within the file.

I’ve found that 5,000 lines of XML markup―usually 300-400 KB―is the perfect size for a WordPress import. The file uploads instantly and the PHP import process only runs for 10-20 seconds, well within most server process time limits. The import of each 400KB file runs smoothly and then you can move on to the next small chunk and do it all over again.

Your move, Automattic

I believe that the WP dev team should fix this problem. Granted, they can’t predict the behavior of every server, but they could build some sort of sectioning and redundancy into the import process.

  • Test the XML document for its size.
  • If it exceeds, say, 500 KB, run the import in waves.
  • Automattically (see what I did there) break the large XML doc into chunks.
  • Lather, rinse, repeat.

WordPress could do this for you. But right now it doesn’t. And I think that’s a shame. Hopefully this tutorial saves some headaches.

24 thoughts on “WordPress Import Failed? Here’s How to Fix It

  1. Chris

    Thanks for that post! I guess that you can also reduce the processing time by unchecking the option to import attachments (You can process those attachments later with plugins). I totally agree that the import procedure could be improved for people who have to rely on shared hosting where you cannot change the php execution time. It would probably be possible to process the items one by one with AJAX.

    Reply
  2. cto

    i was having this problem and the solution was to delete all the spam comments from my XML file.

    THANKS A LOT for the leads

    Reply
  3. Muhammad

    Hey TJ,

    You just saved my life!

    Thank you for your time taken to write this out. I thought your 100,000 line XML was crazy but i realised that I had 140,000. Haha!

    Have an awesome day.

    Reply
  4. KMHDESIGN

    I second that motion! Awesome helper, I haven’t tried it yet, but i have to say, its the first rational thing i’ve seen in all the searching i’ve done. And this post is how old? I wish i’d have found it first!
    Im simply trying to load demo content for a theme (hate recreating post layouts, etc) so nothing critical like most people moving blogs. None the less, This is super valid information!
    Thank you!
    KMH

    Reply
  5. Mick

    Just run the importer many times until you get it all. Works every time for me. Last one i did succeeded on the 3rd run!

    Reply
    1. TJ Kelly

      Thanks for your comment, Mick. That plan fails if the server kills the process and errors out. That’s what happened to me every time. Otherwise, a good idea. Thanks!

  6. Mick

    When the server kills the process and errors out, it doesn’t undo what it got done in that time. So incrementally running it till error you eventually get everything across. It can take many times if its a large xml but this method hasn’t failed on me yet. Some menu duplication occurs but thats the only negative I have found which is an easy fix.

    Reply
    1. TJ Kelly

      Hmmm an interesting point. I’ll have to try it. Also, what’s your easy fix for the duplicate menus? Manual recreation/purging?

  7. giovannif23

    Something that has worked for me is the following:

    1. Import the demo xml files on a local server. (I usually never receive a timeout error).
    2. Export local SQL and save to file.
    3. Open SQL in text editor (Sublime) and change all of the URLs using common + F (from localhost to server URLs).
    4. FTP the /uploads/ folder to live server
    5. Upload SQL using phpMyAdmin import.

    I’m my experience the timeout issues have been caused by attaching/importing the images. I hope that this approach might help someone else. :)

    Reply
  8. Adam Watts

    Working on a 3,000,000 line text file…thought I’d try and make everyone’s lives seem better after reading this. Up to about 250 files that it’s been split up into…still working….

    Reply
  9. CrazyTom

    Had the same problem, importer kept cutting off my latest posts. Found exporting between dates (i,e. one month at a time) worked fine. Don’t know if it works for pages, but a good time saver!

    Reply
  10. Max

    i found a much better solution i cannot remember where but it works like a charme!
    all you have to do is tar compress the exported .xml file and voilá!
    i use this command from the mac os terminal:

    tar -cvzf x.tar.gz *.xml

    take care i use the * wildcard so every xml file will be compressed so use it inside a new empty folder with just the xml file you want to use

    Reply
  11. salem

    I can’t believe it WP import tool support compressed files . they didn’t mention it on support document!
    Thanks Max you save my day I was havein 3.8MB xml file and I compress it to .gz using 7ip and wordpress accept it with no issue .
    TJ Kelly Pleas Update your post with Max solution it realy works .

    Reply

Leave a Reply

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