Support

Account

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);