wp import
Overview
Import posts, pages, custom post types, terms, and comments from a WXR XML file into WordPress. Requires the WordPress Importer plugin to be active.
What It Does
wp import runs the XML through the WordPress Importer plugin, inserting content into the destination WordPress database. Author handling is configured via the --authors flag.
Syntax
wp import <file> --authors=<mode>
Arguments & Options
| Flag | Description |
|---|---|
FILE | Path to the .xml WXR file to import |
--authors=MODE | How to handle authors: create, mapping.csv, or skip |
--skip=ITEMS | Comma-separated items to skip: image_resize, attachment |
Author Modes
| Mode | Behaviour |
|---|---|
create | Create new user accounts for any authors found in the XML |
skip | Skip content with authors that don't exist on the destination |
mapping.csv | Provide a CSV mapping file of old → new author logins |
Basic Usage
Import with author creation
wp import /tmp/export.xml --authors=create
Import skipping unknown authors
wp import /tmp/export.xml --authors=skip
Import with author mapping file
# mapping.csv format: old_login,new_login
# e.g.: sarah,sarah_new
wp import /tmp/export.xml --authors=mapping.csv
Prerequisites
The WordPress Importer plugin must be installed and active:
wp plugin install wordpress-importer --activate
Real-World Scenarios
Scenario 1: Full content migration
# Install importer
wp plugin install wordpress-importer --activate
# Import all content, creating authors
wp import /tmp/migration.xml --authors=create
# Verify
wp post list --post_type=post --format=count
wp user list --format=count
Scenario 2: Import with author mapping
# Create mapping file
cat > /tmp/author-map.csv <<EOF
old_admin,new_admin
sarah.jones,sarah
bob_writer,bob
EOF
wp import /tmp/export.xml --authors=/tmp/author-map.csv
Scenario 3: Import without media processing (faster)
wp import /tmp/export.xml --authors=create --skip=image_resize
Scenario 4: Import multiple split XML files
for file in /tmp/exports/*.xml; do
echo "Importing: $file"
wp import "$file" --authors=skip
done
Best Practices
- Install the importer plugin first — import will fail without it.
- Use
--authors=skipwhen the destination has the same users already. - Use
--authors=mapping.csvfor migrations where usernames changed. - Run
wp search-replaceafter import if the source URL differs. - Import media separately via
rsyncof theuploads/folder.
Post-Import Checklist
# 1. Check post counts
wp post list --post_type=post --format=count
# 2. Update URLs if domain changed
wp search-replace 'https://old-site.com' 'https://new-site.com' --skip-columns=guid
# 3. Flush permalinks
wp rewrite flush
# 4. Flush cache
wp cache flush
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: WordPress Importer not active | Plugin missing | wp plugin install wordpress-importer --activate |
Error: parsing XML | Malformed or corrupted export file | Re-export from source site |
| Duplicate posts after import | Import run twice | Check with wp post list before re-running |
| Images show as broken | Files not copied | Sync uploads/ with rsync |
Quick Reference
wp plugin install wordpress-importer --activate
wp import export.xml --authors=create
wp import export.xml --authors=skip
wp import export.xml --authors=mapping.csv
wp search-replace 'https://old.com' 'https://new.com' --skip-columns=guid
wp rewrite flush && wp cache flush
Next Steps
wp export— generate the XML file to import.wp search-replace— update URLs after importing.