Support

Account

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

Solving

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);
      }
    }
    
  • I second the opinion that deleting rows is not working for a Repeater field in a OPTIONS page.

  • CHRIIIIIST!

    I was using options, the correct post_id is option.

    It’s the same issue as the guy in the main thread.

    I ended up using: while(delete_row('my_repeater_field', 1, 'option'));

    Notice it’s option! Not options!!

  • In my case there was one more thing.

    I was updating another field from the same Option page. I created another Option page just for this field, outside the same option page. After this, everything I’ve been trying to do in the past 6h just started to work.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Deleting rows on options page programmatically doesn't seem to work’ is closed to new replies.