Transfering posts from one custom post-type to a different one

Transfering posts from one custom post-type to a different one

The problem

When you change the theme on a WordPress installation that heavily depended on custom post-types —to show product/portfolio items, for instance— you might find that they won’t be using the same slug for this custom post-type. This means that your existing items will not be accessible from WordPress’s control panel with the new theme installed.

Showing old items

With the Custom Post Type UI plugin, you’re able to manage all custom post-types that the WordPress database contains. By creating an entry with the slug of your former custom post-type you’ll be able make them show up again in the menu bar on the left, and even edit them.

It will look something like this:

CPT-UI

But they’re still not showing as your new theme’s custom post-type.

Actually transfering custom post-types

To transfer your items into your new theme’s custom format is as easy as one mysql line. The idea is to convert all those “portfolio” entries to “project” entries, or whatever your old and new slugs are.

For this you’ll need access to the mysql console or a phpmyadmin installation and type in:

UPDATE `index_posts` SET `post_type` = "new_slug" WHERE `post_type` = "old_slug";

Where index, new_slug and old_slug are to be substituted with you WordPress tables’ index, the slug used for custom post-types on your new theme and the slug from the previous theme. The lines reads something like: “Update all posts with new_slug wherever it says old_slug“.

In phpmyadmin this would look something like this:

Screen Shot 2014-04-12 at 17.58.50

And you’re done. Next time you refresh the Dashboard your old items will now appear under the new theme’s custom post-type.

No Comments

Cancel