Contentstack is a headless CMS with an API-first approach that puts content at the centre. It is designed to simplify the process of publication by separating code from content.
This project (export script) allows you to export content from WordPress into an XML file and prepare it to be imported into Contentstack. Using this project you can easily export WordPress Users (authors), Categories, Media (assets), and Posts and convert them into a format suitable to be imported into Contentstack.
-
Download this project and run the command given below in a terminal:
npm install
This command will install the required node modules on your system.
-
Export WordPress content into an XML file from the WordPress admin panel.
-
Pass the absolute path of the file to the 'xml_filename' key in the config file.
After performing the above steps, you need to export modules. You can either add all modules or only specific modules to suit your requirements.
Run the command given below to export all the modules:
npm run export
This command will extract data of authors, assets, categories, and posts from the downloaded XML file and convert them in JSON files that is supported in Contentstack. These files are stored in the path mentioned in the 'data' key in the 'config/index.js' file.
Run the command given below to export specific modules:
npm run export <<module name>>
The sequence of modules to be exported can be as follows:
- assets
- authors
- categories
- posts
Modules that you wish to export separately or those that have failed to export (modules are recorded in the error log or in the failed.json file) can be installed with the help of their IDs. These IDs will be stored as comma-separated values in a text file. Now, to export the modules, you need to provide the absolute path of the file that stores the IDs, when running the following command in a terminal:
npm run export <<module name>> <<absolute_path_of_the_file>>
However, if you wish to export the 'categories' module, you need to provide the absolute path of the file that stores the slugs of all the categories (the slugs are stored as comma-separated values in the file), when running the following command in a terminal:
npm run export <<module name>> <<absolute_path_of_the_file (slug for category)>>
You can find the logs of the export process under libs/utils/logs. The files included are 'success' and 'error'. Successfully run processes are recorded under 'success' and the errors under 'errors'.
The logs for failed Media(assets) are recorded in 'wp_failed.json' and is stored under the 'master' folder located where your exported data resides.
Copy the 'contenttype' folder from your project and paste it in the path mentioned in the 'data' key within the 'config/index.js' file. The 'contentType' folder consist of the basic schema of content types which will help you to migrate your data.
Now, run the contentstack-importer script to import the content to Contentstack.
- The internal links will not be updated.
- There is no provision to migrate authors' profile pictures or their social profile details, comments on posts, and pages.
- The author count in XML and MySQL export files are different.
- In XML-based export process, if the version of WordPress is lower than 4, the category description and parent details will be absent.
- Only published posts will be migrated.
This project is covered under MIT license.