Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Paul Yorde
Paul Yorde
10,497 Points

How do I use update_option to give me a new option name each time a form is submitted?

How do I use update_option to give me a new option name each time a form is submitted? The code I'm using now overwrites the database value. Instead I need have a new address saved each time.

The code:

    $py_username = esc_html( $_POST['py_name'] );

    // assign addrss to var
    $address = esc_html( $_POST['address'] );

    //assign JSON object to var using geocodeing function('address') input 
    $address_results = boj_gmap_geocode($address);

    // transfer data to options array
    $options['py_name'] = $py_username;
    $options['address'] = $address;
    $options['coords']  = $address_results;

    // create and name the option_name and set fields with $options array
        update_option( 'py_menu_item', $options );

1 Answer

Matt Campbell
Matt Campbell
9,767 Points

It'll be save_option probably. That'll create a new entry but I am guessing.