Support

Account

Home Forums Add-ons Repeater Field Create New Repeater Row from Front End Form Reply To: Create New Repeater Row from Front End Form

  • Hi Jonathan,

    I think there is an update/change to the code that make the minus 1 to $new_repeater_count unnecessary.

    looking in .//advanced-custom-fields-pro/api/api-template.php for ACF Pro v 5.4.2 – on line 1607 there is this.

    			if( is_numeric($s) ) {
    				
    				// get row index
    				$row_i = intval($s) - 1;
    				
    				// add to name
    				$name .= "_{$row_i}";
    				
    			} else {

    So it seems like the -1 is now built in the code.

    I’m not too thrilled with this, as now I have to remember yet another hidden functionality to the update_sub_field() function.

    I would update Jonathan’s code to something like this.

    $repeater = get_post_meta($orgPost, 'org_users', true);
    $index = (!$repeater) ? 1 : $repeater + 1;
    update_field(ORG_USERS_FIELD_KEY, $index, $orgPost);
    update_sub_field(array(ORG_USERS_FIELD_KEY, $index, ORG_USER_SUB_FIELD_KEY), $user_id, $orgPost);