achttienvijftien / wp-data-migration
WP-CLI commands for exporting and importing WordPress Custom Post Types with metadata
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/achttienvijftien/wp-data-migration
Requires
- php: ^8.2
Requires (Dev)
This package is auto-updated.
Last update: 2026-02-01 15:03:49 UTC
README
WP-CLI command that generates WXR files for WordPress Custom Post Types with meta filtering. Outputs WXR format compatible with WordPress import.
Installation
composer require achttienvijftien/wp-data-migration
Usage
Export
Export posts with optional meta filtering:
wp data-migration export --post_type=<type> [options]
Required argument:
--post_type=<type>- Post type to export (required)
Supported WordPress query arguments:
--post_status=<status>- Filter by post status (publish, draft, etc.)--author=<author>- Filter by author ID--post__in=<ids>- Comma-separated post IDs to include--posts_per_page=<number>- Number of posts to export (-1 for all)--orderby=<field>- Order posts by field (date, title, etc.)--order=<order>- Sort order (ASC or DESC)
Custom meta filtering:
--include-meta=<keys>- Comma-separated meta keys to include--exclude-meta=<keys>- Comma-separated meta keys to exclude
File splitting:
--max_file_size=<MB>- Maximum file size in MB before splitting (default: 15)--output=<filename>- Custom output filename or base name for split files
Examples:
# Export all products wp data-migration export --post_type=product # Export products with only specific meta wp data-migration export --post_type=product --include-meta=price,sku,stock # Export products excluding specific meta wp data-migration export --post_type=product --exclude-meta=internal_id,temp_data # Combine with query arguments wp data-migration export --post_type=product --post_status=publish --include-meta=price,sku # Export with automatic file splitting (15 MB files) wp data-migration export --post_type=product --max_file_size=15 # Export with custom max file size (10 MB files) wp data-migration export --post_type=product --max_file_size=10 # Export with custom base name and file splitting wp data-migration export --post_type=product --output=products --max_file_size=20 # Creates: products-001.xml, products-002.xml, products-003.xml, etc.
Default Meta Exclusions:
The following WordPress internal meta keys are excluded by default:
_edit_lock,_edit_last(editing locks)_wp_old_slug,_wp_old_date(revision data)- Keys starting with
_oembed_(cached embeds)
Import
Use WordPress core import command:
# Install WordPress importer if needed wp plugin install wordpress-importer --activate # Import the WXR file wp import <file> --authors=create
Export Format
Generates WXR (WordPress eXtended RSS) format containing:
- Post data (title, content, excerpt, etc.)
- Post meta (with filtering applied)
- No authors or terms (posts only)
Compatible with:
- WordPress built-in importer
wp importcommand- Third-party WordPress import tools
File Splitting
For large exports, the plugin automatically splits the export into multiple WXR files when using the --max_file_size
option:
- Each file is a valid, standalone WXR document with proper headers and footers
- Files are named sequentially:
export-001.xml,export-002.xml,export-003.xml, etc. - Custom base names are supported:
products-001.xml,products-002.xml, etc. - Splitting occurs when the file approaches the specified size limit
- Each split file can be imported independently or in sequence
- Memory-efficient streaming ensures large datasets (600k+ posts) don't cause memory issues
Development
Running Tests
composer test
Code Quality
# Check coding standards composer lint # Auto-fix coding standards composer format
Requirements
- PHP 8.3+
- WordPress with WP-CLI
License
GPL-3.0-or-later