Home › Forums › Add-ons › Repeater Field › How to add new row at 0 index in repeater field? › Reply To: How to add new row at 0 index in repeater field?
giving it some thought, no, you don’t need to loop at all, or use add_row() or update_row()
Quick example, not precise or including everything.
// this gets the repeater an all rows in an array
$repeater = get_field('repeater_field');
// create a new row, should be same format as returned by above
$new_row = array();
// push the new row onto the beginning of the repeater
array_unshift($repeater, $new_row);
// you can use update field to update the entire repeater at once
update_field('repeater_field', $repeater);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.