I have a theme with around 500 custom options, their code looks like this:

<form method="post" action="options.php">
   <?php wp_nonce_field('update-options'); ?>
   <input type="text" " value="<?php echo get_option('option1'); ?>" />
   <input type="text" " value="<?php echo get_option('option2'); ?>" />        
   <input type="hidden" name="action" value="update" />
   <input type="hidden" name="page_options" value="option1,option2" />
   <input type="submit" value="<?php _e('Save Changes') ?>" />

I guess they're all stored in wp_options table.

The point is, I'm unable to save this data, every time i export/import Wordpress settings these custom options values disappear, changing theme also wipes them out.

How to fix that?

  • How are you saving the data and exporting/importing settings? – EAMann Oct 28 '11 at 17:38
  • I'm exporting WP settings using wordpress/wp-admin/export.php and the custom options are stored like shown above :) – bab Oct 28 '11 at 18:05
  • 1
    That tool exports content not custom options. If your custom options are stored in post-specific custom meta values they'll export, but site-wide options stores in the wp_options table aren't. – EAMann Oct 28 '11 at 18:13
  • EAMann, thank you, is there any way to export these options then? I know it is possible to save them as an array but I guess it will take a lot of work if there is like 500 of them? – bab Oct 28 '11 at 18:16
  • 1
    There isn't a built-in way to export the options table. However, I have seen some themes/plugins add their own export functionality. Basically, you add a button that reads out your options, creates an XML file, and dumps it to the browser. You can then read that XML file back in (again, custom coding), parse it, and re-set your options. – EAMann Oct 28 '11 at 18:18

WordPress is built to import and export content. As such, there is no built-in way to import or export settings.

Some theme and plugin authors, however, have built tools into their systems that import/export XML files that their systems can use store options.

A great example is WordPress SEO by Yoast. Not only can you import/export settings from his plugin, but you can import settings from other systems, too. Yoast's plugin exports an .ini file that contains options and settings in the following format:

; This is a settings export file for the WordPress SEO plugin by Yoast.com - http://yoast.com/wordpress/seo/

version = "1.0.3"

0 = 






This is just one example. My personal recommendation is that you add a button or other trigger that saves your 500 or so custom options in an XML file. You'll have to write this yourself, but it should be fairly straight-forward.

You can then import this same XML file, parse it, and restore your options. Once again, something you'll have to write, but do-able.

If you want to use XML, I recommend you read up on the DOMDocument object that ships with PHP5. It makes creating/reading/manipulating XML documents via PHP pretty easy.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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