I want to export all Wordpress categories (no posts, just categories) from one blog to another. How can I do that ?
migrated from stackoverflow.com Nov 25 '11 at 21:31
This question came from our site for professional and enthusiast programmers.
I solved this problem with 2 queries.
This is not the best way I suppose, but for sure not the safest. Furthermore it assumes that you are working on the same database (if this is not the case you can easily export the query and then import into another db).
I've used it on an empty wordpress installation:
1 - Import the category's terms:
2 - Import categories relationships and descriptions
You cant export only categories (or taxonomies generally). Just export all content with Tools/Export and you can delete content except categories from xml.
What is your end goal here? Just to get a list of categories from one blog to another? Or, are you trying to move all of the content wihtin a category or categories to another WordPress install?
It kinda ugly, but you could export all content, then just delete the content within the categories or delete the categories that you don't want. It would probably be one of the quicker ways to your goal.
If you have access to the database tables you can do a mysql dump export of the wp_term_relationships, wp_term_taxonomy, wp_terms tables and import those into the new wordpress installation. I just did this between two WP installs with over 300 categories and it worked fine.
This answer is essentially the same as Ünsal's, but I'd like to elaborate a bit because despite being right his answer didn't help me (I was just trying to remember what I'd done in the past, I should have read his more carefully and I would have figured it out, but I think for others a full description would be useful).
To export the full category hierarchy you need to export "All Content"
Any other option won't give you the full data (e.g. exporting a post with all categories tagged mostly works, but you lose all parentage/hierarchy data about taxonomies that are hierarchical).
When you export "All Content" the resulting file has a section with data about your terms. If you look through the file it should be easy enough to find, after authors and before "items" (i.e. posts).
You can just import this and delete content if that's an option*
Importing the full file will replicate the taxonomy hierarchy perfectly, but also obviously import all the pages and posts too. If there aren't too many than consider just deleting them by hand. It won't take that long if you do it bulk and there are less than hundreds (remember you can use Screen Options on the Edit Posts screen to show more than the default and thus bulk edit more at a time).
If you have too much content to remove it all then you need to edit the WXR file by hand to remove everything but the terms you want to keep.
Editing the WXR file to remove content
This can be a bit tricky but really if you look at the contents of the file it's not that hard to figure out what each element does. XML is like HTML with tags, so the main thing to be careful of is that you don't delete a closing tag while leaving the opening tag etc.
You'll find that there are 1-3 types of term definitions in the WXR, one type for Categories, one for "tags" and one for "terms". "Custom taxonomies" use terms while old-fashioned categories and tags have their own special format.
CUSTOM TAXONOMY TERM EXAMPLE
So what you want to do is remove all content other than these category/tag/term tags from the WXR file. Namely wp:author tags that come before and the many item tags that come after. Most importantly: Don't remove the closing /channel and /rss tags at the bottom! Without them the XML won't validate.
OBVIOUSLY you will test the results of importing your edited file before using it on a live website. Try importing it into a fresh install locally and see if it fails completely, then check the categories listing screen in wp-admin and make sure everything is exactly as you expected.