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 🙂