I'm writing a course information plugin. Most course info is related to to a post (a custom post type of 'course'), so I have put the majority of info in the postmeta table. But some info isn't related to any of the posts - venue information for example. I'm using the options table to store that info.

I've added a set of options pages, and am using the settings API to edit basic information. The problem is that some of the info is dynamic and more complicated:

I have a venue page where I need to support adding new venues, and editing them. Each venue has a title, 3 address lines and a postcode. An example of the array of venues is:

    1 => array(
                'venue_title' = 'Edge Hill University, Ormskirk',
                'address_1'   = '20 Edge Lane',
                'address_2'   = 'Ormskirk',
                'address_3'   = 'Lancashire',
                'postcode'    = 'L12 6EA'
    2 => array(
                'venue_title' = 'Edge Hill University, Aintree',
                'address_1'   = '12 Aintree Close',
                'address_2'   = 'Aintree',
                'address_3'   = 'Liverpool',
                'postcode'    = 'L48 6PQ'
    3 => array ( ...etc other venues)


So to make any changes I use text fields. These get handled by the settings api. The name attribute and content are set dynamically from a $_GET variable.

<input type="text" name="venues[<?php echo $venue_id; ?>][venue_title]" value="<?php echo $venues[$venue_id]['venue_title']; ?>" />

which would output as

<input type="text" name="venues[2][venue_title]" value="<?php echo $venues[2]['venue_title']; ?>" />

I only have one set of these fields registered with the settings api, which is where i think the problem is, as when I change one, it removes all the other ones and just inserts the new one.

So in my mind the code above should update just the $venues[2][venue_title], but it overwrites all venues. I think because there is only one set of fields registered it will only update as if there is one set of fields. Does anyone know a simple way to make this work?


1 Answer 1


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.

  • 1
    Hi,I also looking for the same thing. Can you explain how u get it?
    – dev-jim
    Aug 19, 2012 at 15:48
  • Please mark questions as answered once you get an answer that works. Thanks!
    – Otto
    Aug 19, 2012 at 22:19
  • If I had any idea where the button was to do that i would... oh the tick i guess
    – danbrown
    Aug 28, 2012 at 20:40
  • @tc.k here's the other answer for future reference...
    – danbrown
    Aug 28, 2012 at 21:19

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.