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
| Flag | Description |
|---|---|
--dir=PATH | Directory to save the export file (default: current dir) |
--filename_format=FORMAT | Filename template (default: {site}.wordpress.{date}.{n}.xml) |
--post_type=TYPES | Comma-separated post types to export (e.g. post,page) |
--post_type__not_in=TYPES | Exclude specific post types |
--post_status=STATUS | Filter by status: publish, draft, private, etc. |
--post__in=IDS | Export specific post IDs only |
--start_date=YYYY_MM_DD | Export posts after this date |
--end_date=YYYY_MM_DD | Export posts before this date |
--author=LOGIN | Filter by post author login |
--category=SLUG | Filter by category slug |
--max_num_posts=N | Limit number of posts |
--with_attachments | Include 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
- Split large exports by date or post type — single exports over 50k posts can be slow or time out.
- Transfer media files separately — WXR only includes attachment metadata, not the actual files. Use
rsyncfor theuploads/folder. - Use
--with_attachmentsto include attachment information in the XML. - Check file size after export — an unexpectedly small file may indicate a silent filter error.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Empty XML file | Post type filter matched nothing | Verify with wp post list --post_type=TYPE |
| Import fails on destination | Missing WordPress Importer plugin | wp plugin install wordpress-importer --activate |
| Very slow export | Large database with many posts | Split by date range or --max_num_posts |
| Media broken after import | Files not copied | Sync 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.