If I am not mistaken, the settings api only storing one single data array in wp_options table. You can only change the field data in the array.

What if I want to add multiple array in the same table with same array structure but different value.

What I mean is :

$data = array(
    '1' = array(
        'cpt'=> 'cpt1',
        'date'=> 'date1',
        'role'=> 'subscriber'            
    '2' = array(
        'cpt'=> 'cpt2',
        'date'=> 'date2',
        'role'=> 'eiditor'       

and I can add new array, edit the field inside either one of the array,or delete unwanted array.

What I found on goolge are only tutorial on how to store the data in single array, but I did see some plugin done this, but just couldn't understand how they done it with my current of programming level.

I don't want to create another custom table,since the data that I want to store is not so much. I only store some setting (user,post-type,post date) for further use.

Any guides or advice will be appreciated.

2 Answers 2


I put this in the form so it knows its editting:

<form method="post" action="options.php">

     <?php settings_fields('venues_section'); ?>
     <input type="hidden" name="editmode" value="<?php echo $editmode; ?>" />
     <input type="hidden" name="venue_id" value="<?php echo $venue_id; ?>" />
     <?php submit_button(); ?>


The receiving validation function can then handle that by doing something like this:

function venues_validation_callback($input){

    $venues = get_option('venues'); // Get the current options from the db (Edit 
                                    // this and return the full modified version)
    $editmode = $_POST['editmode'];  // add, edit or delete     
    $venue_id = $_POST['venue_id'];             

    if($editmode == 'add'){

        // Do Add Logic

        return $venues;

    elseif($editmode == 'edit') {

        // Do Edit Logic

        return $venues;

    elseif($editmode == 'delete'){

        // Do Delete Logic

        return $venues;


    return $input; // only triggered if none of the above are called

That's just to show its possible. There's quite a lot of other ins and outs to it as well its a pretty custom solution. I've got it working but its taken a week and given me a few headaches doing it I'll be honest. But there you go that's about as much as I can do. Hopefully there's a plugin that could do it I hadn't found. It'd be nice to make it if it hasn't already if i had time.

  • danbrown,I just got the time to revisit this issue (I was busy with something else). I can tell what your codes are trying to do, but now my major problem is not able to figure out how to write the action logic codes. Can you show me how you write the Add,Edit,Delete logic codes? Thanks
    – dev-jim
    Commented Sep 14, 2012 at 18:15

I just found a way of doing what I think you're after... otto just helped me out with it here.

"Look at your validation function (the one referenced by your register_setting call). Whatever it returns replaces the entire setting in the database. So if it's not getting the setting and then altering it and returning the entire setting, you'll lose the data that you didn't have it return."

So you can do all the manipulating of the array there...

  • From the link, I can see how to manipulating the input data for saving, but what if we want to delete some of the records?
    – dev-jim
    Commented Aug 19, 2012 at 17:35
  • If I understand you right you can use the validate function to do deleting as well. Could you give an example? It is multiple arrays you want in the same options field?
    – danbrown
    Commented Aug 20, 2012 at 8:37
  • yes, it suppose are multiple arrays. Each array represent a rule (eg,user,gender,age). So if I have many user, then I will have many rules. What I want is able to add, delete, update and read each of the array(rule).
    – dev-jim
    Commented Aug 20, 2012 at 10:40
  • You can definately do it in the validate callback, I've just set it up - add, edit and delete. You need to let the validate function know whether it should add or edit or delete. I did it by putting an extra hidden field in the forms, I'll put it in an answer...
    – danbrown
    Commented Aug 22, 2012 at 13:07

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.