TJ Kelly

WordPress Import Failed? Here’s How to Fix It

[blog_stripe html_class=”light-grey”]

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:

[/blog_stripe]

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.

[blog_stripe]

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.

[/blog_stripe]

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.

40 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
  12. Irish Damsel

    your tutorial is a blessing! I tried in vain repeatedly trying to import of a 5,000 KB XML file and it didn’t work. Thanks for going through the process for us, I will try it and see if it works this time. Shame that WordPress doesn’t offer to do this for us. I guess there’s some small gain to a loss- I’m learning something new.

    Reply
    1. TJ Kelly

      Glad it helped, @irishdamsel:disqus. But keep Mick’s proposal below in mind: you can just keep trying the same single (large) XML file over and over. WP will skip the parts that have already been imported and pick up where it left off, until it fails again. Rise, repeat.

      I actually use that method nowadays most of the time. I only use my method above if the data needs to be brought over with surgical precision.

      Thanks for your comment!

  13. Brianna

    For those who come across this tutorial… know that there are free programs that will do the splitting for you – no need for manually editing the xmls. Just search for “WXR splitter” to find a recent version that works with your computer. Enter a max file size, and a few moments later you’ll have your smaller chunks.

    Reply
  14. Burgerdogboy

    My problem is kinda strange. The file has entries stating back to 2009 up thru today. But when I import it to a new theme, none of the entries past 2012 show up!

    Reply
    1. TJ Kelly

      Thanks for your comment, @Burgerdogboy:disqus. Great username, btw.

      Are you importing WP content via the XML file? Or just activating a new theme? Can’t quite tell from your wording.

      The import and the theme are totally separate. If the posts are limited to 2012 and newer, that probably points to a timeout.

      I’d try running it again. It should just skip everything from 2018-2012, and start fresh at 2011.

      If not, you can follow the steps I outlined to edit your XML file and remove everything that’s already been imported.

    2. TJ Kelly

      Again— your wording makes things unclear. In strict WP terminology, and XML file can’t be imported into a *Theme.*

      Content can be imported, and Themes can be uploaded/installed. But those are 2 separate processes.

      Is this just semantics? Are you saying that you have a new website (which probably has a new theme) and you’re just trying to import all your old content into that new site?

      If that’s the case, please repeat the steps I mentioned in my comment a week ago: run the import over and over again. It should incrementally work its way through the whole XML file and eventually import everything.

      If not— you may have a bigger problem.

    3. Burgerdogboy

      Have installed a new theme. Earlier, exported content from old theme. Desire to import content to use into new theme. The reason I just didn’t change themes is I am building out the new theme in a different URL as it requires substantial customization.

    4. TJ Kelly

      Thank you for clarifying. Have you tried to re-run the import process a few times in a row?

      Are you seeing any error messages when you run the import? Screenshots or copy/paste would be helpful so we can see what you see!

    5. MrPete

      That makes no sense. You don’t import content “to use in new themes.”
      You import content. And, separately, you can apply themes to the SITE. Not to “content.”
      Your site has one and only one theme active at any time. ALL content is made visible via that theme. And the theme has exactly nothing to say about importing content.

      Hope that helps!

  15. Amanda Wendt

    Hi TJ! I’m having this issue with Blogger Importer to WordPress. I was able to increase the Max size of the uploaded file to 64MB in my Control Panel of my site. But I think the Blogger Importer tool is broken. It hangs up and won’t import. I did import a portion of this blog site back in July and it was a dream. Super fast. Now I’m trying to pick up where I left off, and it just won’t import. I get error and hang ups. Should I chunk the XML file for a Blogger Import or won’t that work?

    Thanks!

    Reply
    1. TJ Kelly

      Thanks for your comment, @amanda_wendt:disqus. Hard to say for certain, but if you had success a few months ago and are hitting trouble now, that points to a conflict somewhere on the server.

      [I don’t know your level of expertise in this, so I’m going to write my response catering to a beginner/novice level. Apologies if that’s aiming too low.]

      —Path-of-least-resistance Answer—

      It’s worth a shot trying one XML chunk and seeing if that makes a difference.

      If the XML file seems to *upload* properly, but then fail to *import* properly, that points not max_upload_size but to something like *max_execution_time* — how many seconds the server will let a process run before killing it.

      Have you looked into that? It would require a cPanel/config change on your server just like the max_upload_size did — http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time

      —Treat-the-cause-not-the-symptom Answer—

      If the problem is *max_execution_time*—the XML file is taking too long to process—but it *didn’t* take too long a few months ago, that may point to a conflict/error either at the code or server level.

      Has any of the following changed since July? In order of likelihood…

      — New or updated plugins
      — New or updated (active) theme
      — PHP version running on your server
      — Version of WP
      — Server itself (like has your hosting company moved you to a new partition/IP/etc)

      Start by deactivating your plugins (especially any new or newly-updated ones) one at a time and trying after each one is deactivated.

      If still no luck, move on to the Theme. Switch to WP’s default twentyseventeen theme and try again.

      And one note of clarification: just because the XML file may be timing out (taking too long), that doesn’t necessarily mean that there’s a *problem* with plugins/code/server, etc. It just might be that you have a huge archive of posts/media to import, and it takes a while.

    2. Amanda Wendt

      Thank you so much for your quick reply!! I will try what you have suggested…there have been a lot of changes since July, and I had not thought of that previously!

      Appreciate your time!

  16. Fiodor Trofimov

    Hi there!
    Thanks for this article, it was very helpful for me. Did the job with 7 chunks 😏

    Cheers!

    Reply

Leave a Reply

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