I'm not great with PHP. I've just created a WordPress admin options page and it works OK:

// Admin Menu
add_action('admin_menu', 'my_cool_plugin_create_menu');
function my_cool_plugin_create_menu() {

    $parent_slug = 'test-slug';
    $capability = 'administrator';

    // sub menus
    add_submenu_page( $parent_slug, 'Test', 'Test', $capability, 'test', 'hp_settings_page');

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

function cm_register_settings() {

    // title
        'mytheme_group',                 // Option group 
        'mytheme_title',                 // Option name
        'admin_options_sanitize_text_1' //sanitize callback

    // IDs

// Admin Page
function hp_settings_page() { ?>

    <div class="wrap">


        <form method="post" action="options.php">
            <?php settings_fields( 'mytheme_group' ); ?>
            <?php do_settings_sections( 'mytheme_group' ); ?>
            <table class="form-table">                 
                    <th scope="row">Title</th>
                        <textarea name="mytheme_title" rows="10" cols="100"><?php echo get_option('mytheme_title'); ?></textarea>

                    <th scope="row">IDs</th>
                        <textarea name="mytheme_ids" rows="10" cols="100"><?php echo get_option('mytheme_ids'); ?></textarea>

            <?php submit_button(); ?>



// sanitize 1
function admin_options_sanitize_text_1($input) {    
    $new_input = sanitize_text_field( $input );     
    return $new_input;

// sanitize 2
function admin_options_sanitize_text_2($input) {    
    $new_input = preg_replace("/[^0-9\,]/", "", $input );       
    return $new_input;

This creates two rows in the database and I can display the values like this:

echo get_option('mytheme_ids');
echo get_option('mytheme_title');

What changes do I need to make to this code so it saves it to one row in the database as an array? So I can then display the values something like this:

$options = get_option('mytheme_options');
echo = $options['ids'];
echo = $options['title'];

Any help appreciated.

1 Answer 1


You only need to register one setting and then just modify your form inputs to save the values into an array. Here's an example of registering the setting:


$mytheme_settings = get_option( 'mytheme_settings' );

and the field markup:

<textarea name="mytheme_settings[title]">
    <?php echo esc_textarea( $mytheme_settings['title'] ); ?>

You'll also need to combine your sanitize functions, modifying them to work with the values in the new array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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