I have been struggling with this one for about a week now. I would like to have 2 variables available on a settings page, but I cannot figure out how to do this using the Settings API.

Perhaps there is a better way to do this. What I am trying to do is have one variable that stores a list of sortable values which I am outputting in a table and using jQuery sortable to allow the user to sort. But I also have some related options (such as title for the section) that are not sortable, so I want to store them in a separate variable and output them normally using add_settings_field which is where things break down. The minute I add a second settings_fields() call in the callback function below, it will allow me to set the options covered by the last settings_fields() call. Obviously since the settings_fields() adds the nonce, action, and option_page fields tot he page the second one is overriding the first call.

So how do I include a second options variable on a settings page?

Here is my code so far:

Adding the submenu page:

        'Gallery View Options',
        'Gallery View',

Register the settings variable:

register_setting( 'crest-feed-gallery-group', 'crest_gv_options' );  // need to add validation!

Callback function for submenu page creation:

function crest_feed_menu_gallery_view_page() {

    $options = get_option('crest_gv_options');
    <div class="wrap">
        <div class="sir-crest-plugin-icon">
            <img src="<?php echo CREST_PLUGIN_DIR . '/images/admin-icon-large.png'; ?>" height=32 width=32 />
        <h2><?php _e('Gallery List Items & Options'); ?></h2>
        <form method="post" action="options.php"> 

        submit_button('Save Gallery View Options'); 
        settings_fields( 'crest-feed-gallery-group' ); 

        crest_drag_and_drop($options, 'gv');  // this function creates the table of sortable values

        submit_button('Save Gallery View Options'); 

  • Have you seen this? – fuxia Jun 24 '13 at 16:39
  • @toscho Very detailed answer. Thank you. So if I am understanding correctly what you are basically saying is don't use the Settings API at all in this instance? – MatthewLee Jun 24 '13 at 17:04
  • You can use it if you want. Or just create a simple form and submit it to admin-post.php. – fuxia Jun 24 '13 at 17:20

Your Answer

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

Browse other questions tagged or ask your own question.