Support » Fixing WordPress » Multiple arrays in one admin option from theme options page.

  • I am trying to create a multidimensional array in the wordpress database from the options pages. I have the form tag

    <form action=”options.php” post=”post”>
    I get the options by

    <?php settings_fields( 'theme_styles' ); ?>
    <?php $options = get_option( 'theme_styles_options' ); ?>

    I have a field

    <input type="text" id="theme_styles_options[option_name]" name="theme_styles_options[option_name]" class="regular-text" value="<?php esc_attr_e( $options[option_name] ); ?> />

    I would like to be able to have this field multiple times but under different arrays e.g.

      'first_array' => array(
        'option_name' => 'value1'
      'second_array' => array(
        'option_name' => 'value2'

    I know at the moment it my current code saves as

      'option_name' => 'value1'

    How to I set my field to send the value to the options.php page to be saved as a multidimensional array? Also, if someone knows how to save it, how to I retrieve it from the field in the database?

    Many Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • This is only a partial answer, but you can store array(s) in the wp_options table by using the PHP function serialize().

    When you retrieve the option, you use unserialize to convert it back to the original array(s).

    This is a recent post, it has code for a nice theme setup page, it uses the option array, like in your example!

    There is a working twenty eleven child theme as a download, the template files have calls to the option array, so if you can follow the code it will give you just what you want!

    Look at the functions:

    Then there is some more in functions.php and the other files!

    In short it saves the values into an array and saves the array in a single option value.



Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple arrays in one admin option from theme options page.’ is closed to new replies.