Monday, June 22, 2015

How to set name of the wxr file when exporting blog data using wp-cli

By default (actually, you cannot change right now), when you export blog data usingWP-CLI, the wxr will be name as following:


1. Clone the wp-cli project:

$ git clone

2. Install composer and install WP-CLI's dependencies:

$ curl -sS | php
$ sudo mv composer.phar /usr/local/bin/composer
$ cd /path/to/wp-cli/src/
$ composer install

3. Modify the get_filename_template function in /path-to-wp-cli-src/php/commands/export.php. For example, I want to name the exporting file after the blog's path: blog-1-path.xml

$ nano /path/to/wp-cli/src/php/commands/export.php
private static function get_filename_template() {
$export_file_name = get_bloginfo('url') . ".xml";
$export_file_name = str_replace("http://", "", $export_file_name);
$export_file_name = str_replace("/", "", $export_file_name);
if( is_multisite()) {
$export_file_name = str_replace("", "", $export_file_name);
return $export_file_name;

4. Then run the export command to see the result

$ /path/to/wp-cli/src/bin/wp export --path=/path/to/wordpress/root --dir=/path/to/export/ --url=

You will have a backup file names blog-1-path.xml. Pretty neat huh?