Support

Account

Home Forums Add-ons Repeater Field Nested repeater and programmatically add values Reply To: Nested repeater and programmatically add values

  • Please note the documentation that you must use field keys when adding values where they do not already exist. When using update_field() it is always safest to use field keys instead of field names.
    Also note that the values you supply must be in the same format that ACF stores in the DB and NOT what you have set for the return format. I do not know what format this is for the time field. You should look in the database and make sure you are matching the value.
    I would also suggest using a different sub field name for your repeater than then parent repeater name. Using the same name could potentially cause issues when using nested have_rows() loops.
    To update a repeater field the value must be:

    
    // you should replace all the field names with field keys
    $value = array(
      // nested array for each row of the repeater
      array(
        // field_key => value pairs for the row
        'day' => 'DAY VALUE',
        'working_hours' => array(
          // this is a nested repeater, it follows the same pattern as the parent repeater
          // nested array for each row
          array(
            // field_key => value pairs for the row
            'from' => 'TIME',
            'to' => 'TIME'
          }
        )
      )
    );
    update_field('working_hours', $value, $post_id);