WordPress upgrade to 2.6 deletes all Categories
Monday, August 4th, 2008
After not having updated WordPress for a while (we were still on 2.3), the new WordPress iPhone Application convinced us that it was about time.
Unfortunately, all my categories were missing after the upgrade. Seems like the wp_categories table got removed an replaced by wp_terms and wp_term_taxonomy. The entries are still there, just without name and descriptions.
Fortunately there are ways to fix it (if you have a backup, harhar).
David Cumps wrote a nice post about how to fix it manually, but if you have lots of Categories, you can do it automatically too (if you prepare of it).
First step (before the upgrade) is to save a version of the wp_categories table:
mysqldump -uUsername -pPassword wordpress_db
wp_categories > wp_categories.sql
After the upgrade you have to play it back and run the following two queries:
mysql -uUsername -pPassword
wordpress_db < wp_categories.sql
UPDATE wp_terms, wp_categories
SET wp_terms.name = wp_categories.cat_name,
wp_terms.slug = wp_categories.category_nicename
WHERE wp_terms.term_id = wp_categories.cat_ID
UPDATE wp_term_taxonomy, wp_categories
SET wp_term_taxonomy.description =
wp_categories.category_description
WHERE wp_term_taxonomy.term_id = wp_categories.cat_ID
If you didn’t make a backup of the wp_categories table, you can just load the whole backup again and give it a different name. When you run the 2 queries, just prefix the table names with the name of the backup DB.
Update: If you have subcategories, you can try the query I posted in my comment below. I didn’t actually try it myself, so be careful.
