Support

Account

Home Forums Add-ons Repeater Field Delete rows from repeater fields custom code

Helping

Delete rows from repeater fields custom code

  • Hello,

    I’m adding rows dynamically using custom code

    Now i want to remove the rows from the repeater field except the first one with empty values. ScreenShot

    Can anyone help me deleting rows from repeater fields?

    Thanks

  • Hi @rizwan157

    I believe you can do it like this:

    // set the object ID
    $post_id = 99;
    
    // this gets the repeater and all rows in an array
    $repeater = get_field('repeater_field', $post_id);
    
    // get the first row
    $first = array_shift($repeater);
    
    // update the repeater with the first row only
    update_field('repeater_field', $first, $post_id);

    Where ’99’ is the object (post/page) ID you want to update.

    I hope this helps 🙂

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

The topic ‘Delete rows from repeater fields custom code’ is closed to new replies.