WP-CLI Import Content

Rather than using the WordPress admin to import a WXR file, you might find it helpful to use WP-CLI instead.

By importing with WP-CLI instead of the WordPress admin, you’ll also have additional options available to you, such as skipping certain types of data.

Importing WordPress WXR (.xml) Files

To perform a simple import of your file, just use the following command:

wp import my-file.xml
Shell

Modifying Author Behavior

When importing a WXR file, you might have a situation where the post author in the export file doesn’t exist on the site that it’s being imported into. In that case, you can use the –authors option to define how to proceed with the import.

Creating Non-Existent Authors

If you want to create any authors that don’t already exist, set value of the –authors option to create like this:

wp import my-file.xml --authors=create
Shell

Skipping Non-Existent Authors

If you’d like to just leave the post’s author empty if the user doesn’t already exist, you can set the value of the –authors option to skip:

wp import my-file.xml --authors=skip
Shell

Custom Mapping Authors

What if you want to associate your authors from the exported site with different users on the new site? WP-CLI allows for a custom CSV file to be provided. The CSV should be formatted as 2 columns with old_user_login and new_user_login as column headers like this:

old_user_login new_user_login
user1 newuser1
anotheruser somethingelse

To use the custom user mapping that you’ve defined within the CSV, just define the path within the –authors option like this:

wp import my-file.xml --authors=my_file.csv
Shell

Skipping Content Types

When performing an import of your WXR file, you also have the option to skip certain types of data, such as attachments or thumbnail generation.

Skipping Attachment Imports

If you don’t want to import any of the attachments that are listed inside the WXR file, you can use the –skip option with the attachment data type like this:

wp import my-file.xml --skip=attachment
Shell

Skipping Thumbnail Generation

What is you still want to import your post attachments but don’t want to generate new thumbnails when the import occurs? Just use the –skip option with image_resize as the value like this:

wp import my-file.csv --skip=image_resize

Leave a Comment