
When migrating a WordPress site or splitting it from a multisite network, sometimes you need more control than the built-in Tools → Export/Import option. In those cases, you can export and import posts directly at the database level using phpMyAdmin or MySQL.
This guide walks you step-by-step through the advanced method of handling WordPress posts, metadata, categories, and thumbnails.
Understand Where WordPress Stores Posts
WordPress doesn’t keep posts in just one table. When you export/import posts manually, you need to take care of multiple tables:
Table | Purpose |
---|---|
wp_posts | Stores all posts, pages, custom post types, and media attachments. |
wp_postmeta | Stores metadata for posts (custom fields, featured image _thumbnail_id, etc.). |
wp_terms | Stores categories and tags. |
wp_term_taxonomy | Defines taxonomy types (category, tag, custom taxonomy). |
wp_term_relationships | Connects posts to terms (e.g., which category a post belongs to). |
⚠️ Note: Your table prefix may not be wp_. If your database uses wp_2_ or blog1_, adjust queries accordingly.
Export Posts from the Source Database
You can export directly from phpMyAdmin or the MySQL command line.
Export Posts
Export Post Metadata
Export Categories/Tags
💡 Pro Tip: If you also want images, don’t forget to include posts of type attachment:
Import Posts into the Target Database
-
Open phpMyAdmin on the new site.
-
Go to the database → click Import.
-
Upload each exported .sql file (posts.sql, postmeta.sql, terms.sql, etc.).
-
If you’re using MySQL CLI, run:
4. Fix IDs and Relationships
-
Posts reference thumbnails using _thumbnail_id in wp_postmeta.
-
Categories and tags reference posts using object_id in wp_term_relationships.
-
If the target site already has content, IDs may conflict. In that case, you may need to remap IDs using a script or plugin like WP Migrate DB.
5. Move Media Files (Images)
The database only stores references to images — the actual files live in /wp-content/uploads/.
-
Copy the entire uploads/ folder from the old site to the new one:
-
Ensure correct file permissions (755 for folders, 644 for files).
6. Update URLs if the Domain Changed
If the new site has a different domain, update old URLs inside the database.
This ensures images and internal links point to the correct domain.
7. Regenerate Thumbnails
Since WordPress stores thumbnails as physical image files, after moving media you should regenerate thumbnails.
-
Install the plugin Regenerate Thumbnails.
-
Run it to rebuild all image sizes.
8. Test the Import
-
Visit your new site → Posts → check if all content is present.
-
Open a few posts to confirm:
-
Categories and tags are showing correctly.
-
Featured images are attached.
-
Media loads from /uploads/.
-
✅ Final Thoughts
Exporting and importing WordPress posts directly from the database is powerful but requires care:
-
Always back up both source and target databases first.
-
Make sure you migrate posts + metadata + terms + attachments together.
-
Copy the uploads/ folder, otherwise images won’t load.
-
Run SQL replacements if your domain changes.
-
Regenerate thumbnails for best results.
This method is best for developers and advanced site migrations, especially when splitting a site out of a multisite or merging data between two WordPress installs.