Reputation: 46
Could you help, please, to understand how to save the settings correctly in the next case?
function my_settings_init() { ... register_setting( 'my-settings-group', 'my-settings-name' ); add_settings_field( 'my-field, 'My Field', 'my_field_callback', 'my-plugin', 'my-section' ); ... } function my_field_fallback() { $setting = get_option( 'my-settings-name' ); echo 'input type='text' name='my-settings-name[title]'; echo 'input type='text' name='my-settings-name[slug]'; }
The result array is:
Array ( [title] => title 1 [slug] => slug 1 )
How to use save_callback to make the next result:
Array ( [0] => Array ( [title] => title 1 [slug] => slug 1 ) [1] => Array ( [title] => title 2 [slug] => slug 2 ) ... )
Thank you for your help!
Upvotes: 0
Views: 1444
Reputation: 3124
You're trying to add multiple fields of the same, this can only be done by using wp_ajax_ hook. http://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)
Then in your callback you can have a add new button to create a new set of fields and an update button to save the fields accordingly.
It's better if you save the array as JSON and decode it when you need to append a new array set.
Upvotes: 0