Skip to main content

wp export

Overview

Generate a WXR (WordPress eXtended RSS) XML export file containing posts, pages, custom post types, comments, terms, and post meta. The standard WordPress content portability format.

What It Does

wp export calls the WordPress export API to produce an .xml file that can be imported into any WordPress site. It mirrors the Tools → Export UI but with powerful filtering options unavailable in the dashboard.

Syntax

wp export [OPTIONS]

Arguments & Options

FlagDescription
--dir=PATHDirectory to save the export file (default: current dir)
--filename_format=FORMATFilename template (default: {site}.wordpress.{date}.{n}.xml)
--post_type=TYPESComma-separated post types to export (e.g. post,page)
--post_type__not_in=TYPESExclude specific post types
--post_status=STATUSFilter by status: publish, draft, private, etc.
--post__in=IDSExport specific post IDs only
--start_date=YYYY_MM_DDExport posts after this date
--end_date=YYYY_MM_DDExport posts before this date
--author=LOGINFilter by post author login
--category=SLUGFilter by category slug
--max_num_posts=NLimit number of posts
--with_attachmentsInclude attachment metadata

Basic Usage

Export all content

wp export --dir=/tmp/exports

Export only published posts

wp export --post_type=post --post_status=publish --dir=/tmp/exports

Export pages only

wp export --post_type=page --dir=/tmp/exports

Export content between dates

wp export --start_date=2025-01-01 --end_date=2025-12-31 --dir=/tmp/exports

Real-World Scenarios

Scenario 1: Full content migration to a new site

# Source site
wp export --dir=/tmp/migration --filename_format="migration-full.xml"

# Transfer
scp /tmp/migration/migration-full.xml user@new-server:/tmp/

# Destination site
wp import /tmp/migration-full.xml --authors=create

Scenario 2: Export a single author's posts

wp export \
--post_type=post \
--post_status=publish \
--author=sarah \
--dir=/tmp/sarah-export

Scenario 3: Staged export of large sites (split by year)

for year in 2022 2023 2024 2025; do
wp export \
--post_type=post \
--start_date="${year}-01-01" \
--end_date="${year}-12-31" \
--dir=/tmp/exports \
--filename_format="${year}-posts.xml"
done

Scenario 4: Export specific custom post types

wp export \
--post_type=product,product_variation \
--post_status=publish \
--dir=/tmp/woo-export

Best Practices

  1. Split large exports by date or post type — single exports over 50k posts can be slow or time out.
  2. Transfer media files separately — WXR only includes attachment metadata, not the actual files. Use rsync for the uploads/ folder.
  3. Use --with_attachments to include attachment information in the XML.
  4. Check file size after export — an unexpectedly small file may indicate a silent filter error.

Troubleshooting

ProblemCauseFix
Empty XML filePost type filter matched nothingVerify with wp post list --post_type=TYPE
Import fails on destinationMissing WordPress Importer pluginwp plugin install wordpress-importer --activate
Very slow exportLarge database with many postsSplit by date range or --max_num_posts
Media broken after importFiles not copiedSync wp-content/uploads/ between servers

Quick Reference

wp export --dir=/tmp/                              # All content
wp export --post_type=post --dir=/tmp/ # Posts only
wp export --post_status=publish --dir=/tmp/ # Published only
wp export --start_date=2025-01-01 --dir=/tmp/ # Date filtered

Next Steps

  • wp import — import the exported XML on the destination site.
  • wp db export — full database export for complete migrations.