When migrating your content from one location to another, creating backups, or making mass changes to existing content, you might find the need to export your site's content. While you can always do this from within your WordPress admin, it'll save you a few clicks to do it from within WP-CLI instead.
Inside this article, we'll show you how to perform a WXR export of your WordPress site's content using WP-CLI.
Exporting All WordPress Content
By default, WP-CLI will export the following content:
- Attachment (actual attachment files not included)
To export all of this content, simply use the following command from within your WordPress site's root directory:
Changing Your Export File Path
The export file will be placed within the current working directory. If you want to export the file to another location, you can user the --dir option like this:
wp export --dir="/my/path/here"
Exporting Without Comments
If you have a large number of comments, you might want to exclude them. To exclude comments from your export, use the --skip_comments option like this:
wp export --skip_comments
Exporting Only Posts for a Specific Post Type
To only export posts within a specific post type, you can use the --post_type option. For example, if you only wanted to export pages, you could use the following:
wp export --post_type=page
Exporting Only Published Posts
What if you want to export all posts, but want to ignore any drafts? Simply use the --post_status option like this:
wp export --post_status=publish
Within WP-CLI, there's a multitude of options that can be provided when exporting content from your WordPress site. For further reading, take a look at the official WP-CLI documentation for the wp export command.