Custom Post Types (CPTs) are a fantastic feature within WordPress. They allow you to define your own Post Type and how it operates within WordPress. As an example, if you’re creating a movie review site you might make a Custom Post Type called ‘movies’ and include Custom Meta Boxes and seperate entry fields for data such as “Genre”, “Release Date”, “Director”, etc., rather than adding all the content into the standard edit field. This makes for much easier to manage data when displaying it within your theme.
When CPTs are stored within the WordPress database, the CPT name (ie. the first parameter used within the register_post_type() function) is stored along with the rest of the Post data. If, for some reason, you need to change your CPT name, any data that you currently have stored for that Custom Post will disappear from with the WordPress Dashboard after the name change. In actual fact, the data is still obviously in the database, it’s just assigned to a Custom Post that no longer exists. Getting your data back is a fairly easy process but you do need to be confident with using phpMyAdmin and as a precaution, you should definitely make a backup of your database prior to making any changes.
Within phpMyAdmin, run the following SQL command on your database, replacing custom-post-type-name with the actual name of your Custom Post Type…
SELECT * FROM wp_posts where post_type = 'custom-post-type-name'
After running the above SQL, you should be displayed with a list of your Custom Posts. There are two fields that need to be updated within each Post. The guid field and the post_type field. The guid field contains the URL of your post and as part of this URL, the CPT name is included. The post_type field simply contains the actual name of the Post Type. Simply edit each row of data, carefully replacing the Post Type name in both the guid field and the post_type field. After making the changes, log back into your WordPress Dashboard and you should find that all your Posts are listed once again.
One last important point to remember when creating CPTs, is that the Post Type parameter that you use within the register_post_type() function must be a maximum of 20 characters and cannot contain capital letters or spaces.
I hope you find this useful and if so, feel free to leave a comment 🙂