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
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.
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:
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.