Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

array(
    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?

Thanks

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Thank you you're a genius I just got it working :) –  danbrown Aug 19 '12 at 14:14
    
Hi,I also looking for the same thing. Can you explain how u get it? –  dev-jim Aug 19 '12 at 15:48
    
Please mark questions as answered once you get an answer that works. Thanks! –  Otto Aug 19 '12 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 '12 at 20:40
    
@tc.k here's the other answer for future reference... –  danbrown Aug 28 '12 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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