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 trying to create more than one top level options page in my wordpress theme. But right now I can only save the data for one. How can I save the data for two without having to create tabbed panels?

// create custom plugin settings menu
add_action('admin_menu', 'baw_create_menu');

function baw_create_menu() {

//create new top-level menu
 add_menu_page('BAW Plugin Settings', 'BAW Settings', 'administrator', 'baw-settings', 'baw_settings_page');

//call register settings function
add_action( 'admin_init', 'register_mysettings' );
}


function register_mysettings() {
//register our settings
register_setting( 'baw-settings-group', 'new_option_name' );
register_setting( 'baw-settings-group', 'some_other_option' );
register_setting( 'baw-settings-group', 'option_etc' );
}

function baw_settings_page() {
?>
<div class="wrap">
<h2>Your Plugin Name</h2>

<form method="post" action="options.php">
<?php settings_fields( 'baw-settings-group' ); ?>
<?php do_settings_sections( 'baw-settings-group' ); ?>
<table class="form-table">
    <tr valign="top">
    <th scope="row">New Option Name</th>
    <td><input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Some Other Option</th>
    <td><input type="text" name="some_other_option" value="<?php echo get_option('some_other_option'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Options, Etc.</th>
    <td><input type="text" name="option_etc" value="<?php echo get_option('option_etc'); ?>" /></td>
    </tr>
</table>

<?php submit_button(); ?>

   </form>
   </div>
   <?php 
}


// create second custom plugin settings menu
add_action('admin_menu', 'bax_create_menu');

function bax_create_menu() {

//create new top-level menu
add_menu_page('BAX Plugin Settings', 'BAX Settings', 'administrator', 'bax-settings', 'bax_settings_page');

//call register settings function
add_action( 'admin_init', 'register_settings' );
}


function register_settings() {
//register our settings
register_setting( 'bax-settings-group', 'option_name' );
register_setting( 'bax-settings-group', 'other_option' );
register_setting( 'bax-settings-group', 'etc' );
}

function bax_settings_page() {
?>
<div class="wrap">
<h2>Your Plugin Name</h2>

<form method="post" action="options.php">
<?php settings_fields( 'bax-settings-group' ); ?>
<?php do_settings_sections( 'bax-settings-group' ); ?>
<table class="form-table">
    <tr valign="top">
    <th scope="row">New Option Name</th>
    <td><input type="text" name="new_option_name" value="<?php echo get_option('option_name'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Some Other Option</th>
    <td><input type="text" name="some_other_option" value="<?php echo get_option('other_option'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Options, Etc.</th>
    <td><input type="text" name="option_etc" value="<?php echo get_option('etc'); ?>" /></td>
    </tr>
</table>

<?php submit_button(); ?>

</form>
</div>
<?php 
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

I was able to find the answer!! The problem I was having was having multiple forms being submitted to the options database. I found a tutorial that solved this problem:

WordPress Settings API: Multiple Forms On Same Page

http://www.mendoweb.be/blog/wordpress-settings-api-multiple-forms-on-same-page/

share|improve this answer

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.