Skip to content

How to Import WordPress Posts to a Custom Post Type

WordPress comes with an Export tool that allows users to export content from a site to a WordPress export file. This includes posts, pages, custom post types, custom layouts and media. The Tools menu also has a corresponding Import tool that allows the exported content to be imported to any other WordPress site.

Image of the Tools menu in the WordPress dashboard.

The export tool exports posts to an XML file containing all the content (including comments, custom fields, categories, and tags) but excluding any attachments or media. The posts are automatically assigned to the corresponding post type in the XML file when imported to a different site.

It’s however possible to override this behavior and have the tool import the posts to a different post type. For instance, we can edit the exported file so that regular posts are imported to a custom post type we have created e.g. blog. Here’s how to go about it:

  1. Open the exported XML file using a text editor that has a Find and Replace function, e.g notepad, notepad++
  2. Launch the Find and Replace window and enter the following line to find all mentions of the default post type i.e regular posts:
<wp:post_type><![CDATA[post]]></wp:post_type>
  1. In the Replace box enter the line below replacing blog with the custom post type you want to import to:
<wp:post_type><![CDATA[blog]]></wp:post_type>
  1. Replace all the matches and save the XML file.
  2. Run the import tool and the posts should be imported to the custom post type.

Note: The custom post type should already be present in the WordPress site before importing the file. You can use CPTUI and other similar plugins to quickly create a custom post type.

Tags:
Share:

Leave a Reply

Feel free to share your comments or questions with me. I may not be able to respond immediately so please check later once I've approved your comment.

Your email address will not be published. Required fields are marked *

Kelvin Kathia

Kelvin Kathia is a writer that's passionate about sharing solutions to everyday tech problems. He's the founder and editor of Journey Bytes, a tech blog and web design agency. Feel free to leave him comments or questions regarding this post, or by leaving him a message on the contact page. If you found his content helpful, a donation is much appreciated.