Free Your Content

Freeing Content From Custom Post Types

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
[/php]

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’,
[/php]

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");
[/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.

Food Post Type In TwentyTen Theme

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.

Food List

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.

5 Comments

Tony November 5, 2013

Great post to a problem I was facing. A questions though. I have a theme today with a portfolio post type. If my next theme have a portfolio or gallery post type with a slightly different labels and name. Would it be possible to change the name and labels of the new theme to retreive the old content?

Reply

    Bill Robbins November 5, 2013

    Great question Tony. The labels can be set independently of what whatever the post type is registered as. In the Custom Post Type UI plugin I mentioned, you have the ability to create your own labels and URL slugs. You could take something that’s originally intended for your portfolio and turn it into something for services or a restaurant menu that way.

    Reply

S+ May 7, 2013

This is very helpful! Thank you!

Reply

Leesa April 2, 2013

You’re a lifesaver! Couldn’t work out why I couldn’t just move my custom post types over from my old theme. This worked instantly!

Reply

Submit Your Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get all of our 25 themes (along with future themes) and lifetime updates for only 125 USD.Find out more
+