While developers disagree over whether or not custom post types belong in themes or plugins, most end users don’t care as long as they can access their content. If you’ve added content to a custom post type that’s part of your theme and for some reason you need to change themes, your data won’t be deleted, but you will no longer have a way to access it. Adding that access back is rather simple though. Here’s how.
Find Your Post Type
The first step is to find the post type your missing. To do that, we’re going to need to do some browsing through your old theme. If you have access to a utility that can search for text inside files, what you’ll want to look for is this:[php] register_post_type
The text immediately following this will indicate the actual name of the custom post type. In our Foxy theme for example the registration of our food post type looks like this:[php] register_post_type( ‘food’,
If you don’t have the ability to search across files like that, don’t worry, you can still find it by looking for it. If you still have the theme installed in WordPress, you can use the theme editor to find the code. Go to the Appearance section and select Edit to open up the theme editor. From the list of files on your right, choose functions.php and begin looking through the code there.
It’s possible that the code is there, but it may be placed in another file. Inside of the functions.php file, you’ll find where the theme includes other files too. Those look something like this:[php] include(get_template_directory()."/includes/widgets.php");
That line tells WordPress that the theme also needs to use a file called “widgets.php” inside the “includes” folder. You can then use the theme editor to open up that file. Thankfully most themes have somewhat easy to decipher file names and notes to help you find the right file.
So you should now have your custom post type name. If you are working with more than one type, be sure to get each one’s name.
Install Custom Post Type UI Plugin
Next we’ll want to install the Custom Post Type UI plugin and activate it. This handy tools allows you to add a custom post type via a graphical interface. Once the plugin is active, go to “Custom Post Types” at the bottom of your WordPress control panel and select “Add New.”
Fill in the name for your post type in the top line. You can give them any labels you’d like to. These labels are what will actually appear in your WordPress control panel.
Once you’re finished, click “Create Post Type” and you will now have access to your original content. Here are the menu items I added with our Foxy theme that are now visible in the TwentyTen theme.
An important note about this is while you will have access to your content, this will not preserve any of the styling from the original theme. You will still have access to this content on the front of your site, but it will use the single.php or index.php file (depending on your theme) which will make your post type look like a blog post. Most likely though, you’ll want to either add some customizations to your new theme to make these look like they should or you’ll want to convert these to a post type used by your new theme. Converting post types can be easily accomplished using the Convert Post Types plugin.
So that’s how you can gain access to your custom post type content from a previous theme when switching to a new one. If you have any useful tips, share them with us in the comments.