I'm trying to wrap my head around how to create a set of option fields that should be able to repeat for as many times as possible. But I'm having a hard time to figure out how to proceed.

Currently I've setup the visual interface for administering the options, but I have no idea how to save them into the options on save.

How would a logic look like that will be able to differentiate between different sections? Keeping each section as a separate array within the options array (I guess?) so that you're able to add as many sections that you want, with as many nested data fields as you want.

The idea is quite simple

1) Click add section to create a new section First Step ————

2) A javascript creates the input fields for the section, where you can name.. Second Step ————

3) ..and associate multiple input fields to the section Third Step ————

4) You can also add more sections Fourth Step

The code I have atm is:


function rd_settings_page() {
    <div class="wrap">
        <h2><?php _e( 'Settings', 'blog' ); ?></h2>
        <form enctype="multipart/form-data" action="options.php" method="POST">
            <?php settings_fields( 'rd-settings-group' ); ?>
            <?php do_settings_sections( 'rd-settings' ); ?>
            <?php submit_button(); ?>

function rd_settings_api_init() {
        __( 'Blog info settings', 'blog' ),

    if ( 1 === get_current_blog_id() ) {        
        register_setting( 'rd-settings-group', 'rd_fashion_list' );
        register_setting( 'rd-settings-group', 'rd_blog_description' );

    if ( 1 === get_current_blog_id() ) {        
            __( 'Fashion Blogs', 'blog' ),

add_action( 'admin_init', 'rd_settings_api_init' );

function rd_blog_info_section_callback_function() {
    echo '<p>Blog info settings</p>';

function rd_fashion_list_callback_function() {
    $setting = get_option( 'rd_fashion_list' );?>

    <div class="inner-wrap"></div>
    <span class="addsection button-primary">
        + Add Section



$(document).on('click', '.addsection', function () {
    $(this).prev('.inner-wrap').append('<div class="section">'+
        '<input type="text" name="rd_facebook" id="rd-facebook" value=""/>'+
        ' Name for section'+
        '<option value="" disabled="disabled" selected="selected">Please select a blog</option>'+
        '<option value="1">One</option>'+
        '<option value="2">Two</option>'+
        '<span class="close">×</span>'+
        '<span class="addblog button">+ Add Blog</span>'+

$(document).on('click', '.addblog', function () {
        '<option value="" disabled="disabled" selected="selected">Please select a blog</option>'+
        '<option value="1">One</option>'+
        '<option value="2">Two</option>'+
        '<span class="close">×</span>'+
  • You'll save yourself a lot of trouble if you instead use a plugin like the following: wordpress.org/plugins/fields-framework. It lets you do all that you are trying.
    – user47696
    Commented Feb 16, 2014 at 12:41

1 Answer 1


Not a direct answer to your specific case but this will probably help you figure out how to do it.

I found an article here: http://www.sutanaryan.com/jquery-duplicate-fields-form-submit-with-php/ which details the process of posting fields which can be repeated using jQuery.

In his example he creates an HTML form:

<form action="process.php" method="post">
    <p class="clone">
        <label> Name: </label>
        <input type="text" name="name[]" />
    <p><a href="#" class="name" rel=".clone">Add Name</a></p>
    <p><input type="submit" value="Submit" /></p>

and sets it repeatable:

    var removeName = '<a href="#" onClick="$(this).parent().slideUp(
    function(){$(this).remove()}); return false">remove</a>';

and loops thru each field until there are 0 fields left to loop thru, saving each field to a table within the database.


if(isset($names)) {
    foreach($names as $name) {
        if(strlen($name)>0) {
            $sql=mysql_query("INSERT INTO tbl_name(name) VALUES ('$name')");
        } else {
            echo 'Oops no value to be inserted.';

Searching further I found another article which details a similar process here: I just skimmed it right now but am bookmarking it to read tomorrow.


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.