Hi,
I have a repeater on an options page, and the following function :
function myfunction() {
$rows = get_field('myrepeater', 'options');
if ($rows) {
foreach ($rows as $row) {
// some action
}
}
}
add_action('acf/save_post', 'myfunction');
The action, not detailed in the code above, works just fine.
However, after that i’d like to remove all rows of the repeater on save.
I tried John’s solution from this thread, but nothing happens :
https://support.advancedcustomfields.com/forums/topic/how-do-i-programmatically-delete-all-repeater-rows/
function myfunction() {
$rows = get_field('myrepeater', 'options');
if ($rows) {
foreach ($rows as $row) {
// do something
}
}
$count = count($rows);
for ($index=1; $index<=$count; $index++) {
delete_row('myrepeater', $index);
}
}
add_action('acf/save_post', 'myfunction');
I tried many different things, but nothing happens. I don’t even manage to delete 1 row.
What is wrong ?
OK so i found the problem. Somehow, being an options page, i have to target the page :
delete_row('myrepeater', $index, 'my-options-page');