Home › Forums › Feature Requests › Button to Reset to Default Values › Reply To: Button to Reset to Default Values
The AJAX function
add_action('wp_ajax_my_options_reset', 'reset_default_options');
function reset_default_options() {
// the nonce name here needs to be the same as the
// the nonce name you created when enqueuing the script
if (!wp_verify_nonce($_POST['nonce'], 'my_options_reset_nonce')) {
echo false;
exit;
}
// reset values in a repeater
// this needs to be the name of the repeater
// you want to clear
$repeater = 'repeater_name';
// list of sub field in repeater
$subfields = array(
'campo_teste',
);
// list of other fields to be reset
// this is a list of other fields that
// are not part of a repeater
$fields = array(
'campo_texto',
);
$repeater_count = intval(get_option('options_'.$repeater, 0));
for ($i=0; $i<$repeater_count; $i++) {
foreach ($subfields as $subfield) {
delete_option('options_'.$repeater.'_'.$i.'_'.$subfield);
delete_option('_options_'.$repeater.'_'.$i.'_'.$subfield);
}
}
delete_option('options_'.$repeater);
delete_option('_options_'.$repeater);
foreach ($fields as $field) {
delete_option('options_'.$repeater);
delete_option('_options_'.$repeater);
}
echo true;
exit;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.