Migrating your WordPress website from localhost to a live server or migrating your WordPress website from one server to another is not a very tough task. Migrating a WordPress website can be easily done with the help of backup plugins and cloning techniques. However, the same process cannot be used for all instances. What if you only want to export your Custom Post Type?
Custom Post type mechanism is the perfect way to organize your website, especially if it focuses on more than one subject. By using the Custom Post Type, you will have the power to divide your content based on the information that they contain. If you want to learn more about Custom Post Type creation, please refer “How to Create and Display Custom Post Types in WordPress” article.
In this article, we will show you how to import and export the Custom Post Type in WordPress. We will also show you how to import any custom taxonomies associated with your post types. The import and export of Custom Post Type is a 2 step process. The 1st step involves migrating the actual custom post type and taxonomies. The second step involves the importing of the post type data.
Exporting Custom Post Types and Taxonomies in WordPress :
There are 2 ways to create Custom Post Types and Taxonomies in WordPress. It can be done either by adding code manually in your theme’s functions.php file or by using a site-specific plugin (Custom Post Types UI). In that case, all you need to do is copy that code and paste it on the site where you want to import them. Even if you are not able to find the code, you can still create the same custom post type on another site.
Note: Not all custom post types have taxonomies to export.
For the sake of this tutorial let’s consider the CPT “Mobile” that I have created on my Website. For exporting your CPT all you need to know is your post key value. This is the name used for the post type in your WordPress database. For finding the post key value, you need to see the “post_type=” portion of the URL. The word or phrase after post_type= is the name of the custom post type. In this case, it’s the word, “mobile”.
Once you have the post key, visit the site where you want to import the post type and install and activate the Custom Post Types UI plugin. Upon activation go to Add/Edit Post Types and input the CPT form the old website.
You can follow a similar process for the Taxonomy. You can also get a custom taxonomy key by simply viewing the custom taxonomy in the admin area. For instance, the “Mobile” CPT I created has a section for “Company” to categorize them.
You can add the taxonomy to new website by going into Add/Edit Taxonomies section in the Custom Post Types UI plugin.
If you have more than one CPT or Taxonomy that you want to export than you need to follow the above same for all of them. Also, if you use the CPT UI plugin to create your post type, then you can also use it to migrate them. But this only works if the original custom post type was created using this plugin. Visit the Import / Export section in the plugin settings and follow onscreen instructions.
Exporting or Importing Custom Post Type and Taxonomies in WordPress Theme based sites:
This is also one of the simplest method to import/export Custom Post Types and Taxonomies. WordPress comes with an import/export tool that allows you to export and import WordPress data. For exporting, go to Tools » Export. You can select the “All Content” option if you want to export all your WordPress Data mentioned in that option. Select the “laptops” (name of my CPT) option and click on “Download Export File” button, On Clicking, WordPress will create an XML file and download it on your computer.
For importing, visit the site where you want to import the data. In the target site dashboard, go to Tools » Import. In the Import Section, you will see various options to Import your data.
Click on Install Importer under the WordPress option. After successful installation, click on the run importer option.
On the importer screen, you need to click on the choose file button and then select the XML file you downloaded earlier. Next, click on the Upload file and import button.
On Clicking, WordPress will install Custom Post Type data. WordPress will also automatically add terms to the custom taxonomies.
Custom Post Types & Taxonomies Created by Plugins:
In WordPress, most of the times when you install a plugin, it automatically creates its own Custom Post Types and Taxonomies. These plugin create their own CPT and taxonomies to handle their own content types. If you want to use those CPT and taxonomies on your other site, you don’t need to migrate them manually. You just need to install that plugin on your website. Some plugins also come with import/export option, but if they don’t you can still transfer your Custom Post Type and Taxonomies.
We hope this article helps you clear your doubts. Please drop your queries in the comment section.
Also, if you want us to cover a specific topic, you can drop that in to the comment section as well.