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.
18 Kommentare zu “WordPress upgrade to 2.6 deletes all Categories”
[…] thanks to Remy Blaettler) tags: 2.6, categorie, fix, […]
[…] a more automated approach, take a look at Remy Blaettler’s description of how he achieved the same in a few lines on […]
Thanks a lot for writing this one up.
A life saver as we had 148 cats – much appreciated.
Only small issue – all the cats are now at top level, not in their Sub cats. Any ideas?
I didn’t try this out, because I had no sub categories in my blog, but I think if you copy the category_parent field into the parent field, it should work:
UPDATE wp_term_taxonomy, wp_categories
SET wp_term_taxonomy.description = wp_categories.category_description,
wp_term_taxonomy.parent = wp_categories.category_parent
WHERE wp_term_taxonomy.term_id = wp_categories.cat_ID
Good luck 🙂
[…] Solution 1 Solution 2 Using the Google cache I have pulled my categories up (I could have used my MySQL backup, but the Google cache is faster). […]
[…] The SQL fix is explained here […]
Thanks for sharing 🙂
Be sure to check youre wp_category table for duplicate values in the slug field (its unique in the new table)
[…] Remy Blaettler offered an elegant solution of 3 SQL queries (you’d have to have your wp_categories table backed up before upgrade for a complete […]
Tried it but I still have one strange problem…
Every time I locate the number of a category, and go ahead and try to edit it as in giving it its original name, a number is automatically assigned to it, and therefore it has a new url link that differs from the old one because of that number…
Say I wanted to name a category: (Review) which is its original name before upgrading and the problem… it will end up being (Review 2) because I think wordpress detects another link with the name review, so it gives it a number which messes everything up! Tried everything to avoid the number being assigned, but no use…
Can anyone suggest a solution for that?
Thanks…
Thanks, this is brilliant! Only difference for me was I downloaded my categories as a file and imported it afterwards using phpmyadmin. Ta.
Many many thanks! You saved my 206 categories. 🙂
Very good article
very tthanks for that post, its very useful for me
I needed to upgrade from 2.6. I will be very useful. Thank you very much.
it s very useful, thnxxx
thanks for sharing…
nice sharing..thanks..
Thanks, very useful upgrade, problem solved.