I’ve been working at Automattic (the company behind WordPress.com and many others) for three years now and I’m still living the first statement of our creed:
I will never stop learning.
Today I learned something interesting about WP-CLI and I believe it can help you to import a huge number of XML files to your WordPress automatically just the way it did to me.
Since November 2015, I work as a Happiness Engineer offering support to WordPress.com users but, since early 2018, I’m investing part of my days on
The issue
During one of my shifts working on the second level support, I had to move around 320,000 posts (yup, 320 THOUSAND POSTS) from a site to another one, which is not something as easy as simply exporting database tables due to the relationship of posts created on multiple tables.
Fortunately, there is a tool on WordPress to export and import content by using XML files but I didn’t dare to import 6Gb of XML at once, so I split the file into several smaller ones. 300 files, 20Mb each.
Having hundreds of files to import created another issue
The WordPress native import tool handles only one XML at once.
The solution
I started doing some research to find a better and more
I had used the WP-CLI command `import` to import individual files before but I got excited after reading the <file> description on its documentation:
<file>…
Path to one or more valid WXR files for importing. Directories are also accepted.
Yes! It means the <file> option can also be used to import all XML files added to a
How to use it
- WP-CLI must be installed on your environment (localhost or on your server).
- Create a directory with all the XML files to import on it.
- Run the following command on your terminal
: wp import /directory-path/ --authors=skip --skip=attachment
.
Note that the options `–authors=skip` and `–skip=attachment` are optional and you should remove them depending on your import requeriments.
The full list of options supported by the wp import command is available on the official WP-CLI documentation.
Can you post a step by step tutorial for non techies, please? Would be appreciated.
Hi there!
Thanks for taking some time to comment here 🙂
I think publishing a new post about it won’t help that much because the only steps I can think of are A. Installing WP-CLI on your environment. B. Creating the folder with the XML files.
The steps to install WP-CLI are described on their own site:
https://wp-cli.org/#installing
If you are trying to import files to your local environment, it is possible to create the folder and add all XML files to it by using the file manager installed on your computer (it depends on your SO, though).