Forum Replies Created

  • When using a loop method to delete the rows one at a time, always delete the last row each time, not the first.

    You won’t notice it on small repeaters, but on larger ones it can really bite.

    I used the delete first row method (as is commonly shown online, I think coz it’s easier) and for 376 rows in a repeater, it took 5244 seconds. Deleting the last row each time, it took 191 seconds.

    I do still want to find a faster way. But that was tonight’s optimisation

    Here’s what my code looks like:

    function deleteRows(string $acfRepeaterFieldKey, int $postID): void {
      $fieldValue = get_field($acfRepeaterFieldKey, $postID);
      if (is_array($fieldValue)){
        $remainingRows = count($fieldValue);
        while (have_rows($acfRepeaterFieldKey, $postID)) :
          delete_row($acfRepeaterFieldKey, $remainingRows--, $postID);
Viewing 2 posts - 1 through 2 (of 2 total)