Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
Would saving to Json have any added benefit? –  drtanz Aug 27 '12 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 Aug 27 '12 at 21:06
    
Ok, I'll look into it based on the info you gave me, thanks! –  drtanz Aug 28 '12 at 9:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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