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?
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.
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.
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.
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.