Home › Forums › General Issues › Deleting repeater rows › Reply To: Deleting repeater rows
This is because when you delete the first row (index 0) the second row (index 1) becomes the first row (index 0), the 3rd row (index 2) becomes the 2nd row (index 1), etc. The next iteration of the loop moves on to index 1 and does not repeat index 0, so the loop will only delete every other row.
What you need to do is to get the count of the repeater and loop through it backwards
$rows = get_field($field_key, $thisPost));
if (!empty($rows)) {
$count = count($rows);
for ($x=count; $x>0; $x--) {
$index = $x-1;
delete_row($field_key, $index, $thisPost);
}
}
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.