Custom post type breaks after upgrade to 3.1
I routinely upgraded a client website to WordPress 3.1 today and upon clicking the menu title of my custom post type in the back end, I was met with the error "Invalid Post Type". On the front end side the permalinks were not working either; it was a real mess. OK, stay calm, I backed up the database, so it will be fixable.
3.1 upgrade also causes broken permalinks
The code snippet below also includes the flush_rewrite_rules function which I had recently added to my custom post types article as a result of the permalink structure not working normally. This client's website had been working OK without this function, so I suspect one of the minor 3.0.x releases introduced a code change which makes this function necessary in the event of broken custom post type permalinks.
Change uppercase post type to lowercase
After some searching I came across a post about uppercase custom post type problems with the release candidate of WordPress 3.1. In the case of my client's site, the post type was "Products", so I changed it to "product" in the following line of code
register_post_type( 'product', $args); // add the following function if you are getting // a 'Page not found' error from your permalink flush_rewrite_rules( false );
Update database with new post_type name
None of this will work if your custom posts are sitting in the database with the old post_type value. The following MySQL command can be used to run and 'find and replace' to update all your table rows. I did this via phpMyAdmin by entering the command below into the "Run SQL query/queries on database" field under the view for the wp_posts table.
UPDATE wp_posts SET post_type = REPLACE(post_type, 'Products', 'product')
Update your template files
Lastly, you'll need to update any template files that are calling on the post_type "Products" to now call for "products" in your wp_query functions or wherever else is necessary.
Let me know if you have had a similar experience and if these steps fixed your problems