4

I am following the tutorial here http://wp.tutsplus.com/tutorials/creative-coding/creating-a-simple-backuprestore-settings-feature/

The script shows how to export all options into JSON. Since my plugin creates a custom post type, I would also like to export and import all posts of this custom post type. How can I do that?

1 Answer 1

5

There are two basic approaches you can take.

  1. Use the standard wordpress inport / export plugin manually through the admin. Your custom post type must have the property can_export = true (default = true) If you go this route, there are interesting options for adding extra functionality for users, Check out this tutorial on adding export filters specific to a custom post type
  2. Use a custom export / import method you script yourself. For an example of how this might be done, see the Export to Text plugin. Just download it and read the code. For the import side, you would then examine their suggested import plugin, CSV Importer
4
  • Would saving to Json have any added benefit?
    – urok93
    Commented Aug 27, 2012 at 20:38
  • Not really. Json is a protocol for converting program data into text. So is XML, which is used by WP's built-in import / export functionality. Php supports 'serialize' which also does the same thing. The real trick is to get the data you read and converted from yaml or XML or CSV or whatever format, back into WP as a post -- which requires setting up a a wp_insert_post() call for each one -- including adding all the related post meta, etc. If you don't use the standard XML import, you'll have to custom code your import and export process.
    – marfarma
    Commented Aug 27, 2012 at 21:06
  • Ok, I'll look into it based on the info you gave me, thanks!
    – urok93
    Commented Aug 28, 2012 at 9:15
  • First Link in this answer post is outdated! Commented Feb 17, 2021 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.