8

I am about to begin work on a custom WordPress theme and I want to know how careful I have to be about custom posts. Suppose I create a WordPress theme that registers several custom post types. To my understanding this happens upon activation of the theme.

If I were to create several posts of this custom type and then change to a theme that does not have that custom post type would I have lost the posts completely?

What if I changed to another theme that DID have the same custom post type (if that is possible) would they still exist?

Further, what about these same issues in connection with custom taxonomy? If I change to a different theme that does not support the custom taxonomy will the taxonomy data from custom posts be lost (if they are even saved). Will the data for the custom taxonomy still exist?

  • 1
    Posts are database driven. All the data should be there. Experience is I have changed themes a half dozen times. Think of a theme as a way to view the posts. – Shawn Feb 27 '14 at 22:15
  • If the custom post type is defined Inside the theme folder itself, and you decide to deactivate it, your post type will be "hidden" until you reactivate that theme. The post type will still be inside the database though like the comment above states. – Howdy_McGee Feb 27 '14 at 22:17
  • "To my understanding this happens upon activation of the theme" - it happens at runtime, i.e. when the code is executed, which is every page load. – Andrew Bartel Feb 28 '14 at 0:55
  • 1
    I used to register CPTs in the theme functions files, but have taken to creating them in a mu-plugins folder. In the event of a theme change, templates must be added to display the custom fields associated with CPTs, but the CPTs remain visible in the admin area. – Ray Gulick Mar 4 '14 at 22:14
9

You don't lose anything. All your custom posts, taxonomies, terms and their relationships are still in the database. Without having those registered, however, the data can't be accessed, as in the WordPress edit page or custom queries and the like.

5

As other people have mentioned, if you switch themes in the future all the data will still be in your database but won't be accessible.

For this reason I like to create a functionality plugin that includes all my custom post types, taxonomies and shortcodes. You can even setup a must use plugin that's always enabled in your Wordpress installation. Justin Tadlock wrote an article about creating a custom functions plugin that's well worth a read.

4

What you should do is create a site specific plugin or child theme for your custom code which includes code to register custom post types and custom taxonomy types.

You can then use the code with any parent theme.

As stated previously, nothing is lost as its all stored in the database but clearly will not display in the backend of WordPress unless you use code with the same CPT and Tax names as previously used to register them in the new theme.

2

When you change the theme and the new theme does not have the same custom post type it will not be shown for the new theme. But you easily can get it back if you just copy the code from your old theme for the custom post type and paste it in the new themes function.php file. No data will be lost.

There might be another issue for showing the custom post type on the new theme. But it is guaranteed that no data should lost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.