Custom Post Type UI and WP-CLI
If you weren’t aware, you can actually do a good amount of of administration and site management via your computer terminal console with a tool like WP-CLI. We are not going to go into all of the powerful things it can do out of box, as that’s a documentation site on its own. We are going to highlight the fact that it was made extensible so that plugin authors could add in their own commands to do various tasks.
In October 2018, with the 1.6.0 release of Custom Post Type UI, we added WP-CLI commands for importing and exporting your content type settings. This is what we will highlight here.
As of version 1.12.0, there are two WP-CLI commands available to you, which you can access with the
wp cli command in your terminal. They are
export and each has two flags available to it.
The first flag specifies the content type, is
--type with “post_type” and “taxonomy” available. This flag applies to both
export, and indicates which option we will be importing JSON data into.
The second flag, specific to importing, is
--data-path. This is used to specify where the saved JSON data is located at, so that it can be read and processed. For exporting, the flag is
--dest-path which indicates where to put and save the JSON content as a file.
--dest-pathare relative to your current working directory in your terminal prompt.
Exporting post type settings to a cptui-post-types.json file
wp cptui export --type=post_type --dest-path=cptui-post-types.json
Importing cptui-post-types.json to an install
wp cptui import --type=post_type --data-path=cptui-post-types.json
To work with taxonomies, just change the