Support » Fixing WordPress » Database 'wp-options' table

  • Hi, I’m working on an option for my plugin which allows a user to import/export the settings from the plugin.

    All settings are stored in the wp-options table; and they are all prefixed with a unique set of characters.

    I’m not very savvy with the database interface, but I have seen other plugins perform similar functions.

    1. Is it possible to isolate my plugin options stored in this table; since they are all prefixed with jwl_?
    2. Can I echo these values to a text box, or write to an xml (or similar) file, which can then be used to import the settings?
    3. Could someone suggest the best place to start?

    I know I’ll have to create a form to assist with the import/export. But what is the best way to pull the values? Is get_option my only option?

    Any other information will be most appreciated.

Viewing 1 replies (of 1 total)
  • You can get the options with a standard WP get_results:

    $options = $wpdb->get_results("SELECT * FROM $wpdb->options WHERE option_name LIKE 'jwl\_%'");

    Note the backslash used to escape the underscore.

    This returns an array of objects with the columns of the wp_options table. You should be able to echo these values as you wish.

    EDIT: I ‘borrowed’ code from the Users To CSV plugin by Joost de Valk to create a plugin to export some data for one of my sites.

Viewing 1 replies (of 1 total)
  • The topic ‘Database 'wp-options' table’ is closed to new replies.