Support

Account

Home Forums Add-ons Repeater Field Deleting rows on options page programmatically doesn't seem to work

Helping

Deleting rows on options page programmatically doesn't seem to work

  • I have this code:

    while (have_rows('field_5cd93150df3cf' , 'options')) {
            the_row();
            delete_row('field_5cd93150df3cf', get_row_index(), 'options');
        }

    It only seems to delete a few rows at a time rather than looping through all of them, it seems to work fine on pages that have an id, but using the ‘options’ selector doesn’t seem to work so well.

  • My guess is the way you are attempting to delete the rows. Let’s say that your repeater has 6 rows. After deleting the first 3 it only has 3 rows and calling have_rows() the 4th time returns false because there is no longer a 4th row. However, this is just a guess.

    if this is the case then I would amend the code I posted in the other topic https://support.advancedcustomfields.com/forums/topic/how-do-i-programmatically-delete-all-repeater-rows/ to this to delete the rows starting at the end instead of the beginning.

    
    $images = get_field('images');
    if (!empty($images)) {
      $count = count($images);
      for ($index=$count; $index>0; $index--) {
        delete_row('images', $index);
      }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.