Support

Account

Home Forums Backend Issues (wp-admin) How do I keep content after changing the structure of a repeater? Reply To: How do I keep content after changing the structure of a repeater?

  • Exactly, I’m saying that I would not move the existing fields, I would create new fields and in a creative way allow both the old fields and new ones to be used until such time as the old fields have not value.

    Here’s the thing, to move the content.

    Your old fields, in the database, will have meta keys that look like

    
    "{$repeater_field_name}_{$row_index}_{$sub_field_name}"
    

    These will need to be renamed to

    
    "{$repeater_field_name}_{$row_index}_{$nested_repeater_name}_0_{$sub_field_name}"
    

    in addition to this there is an acf field key reference for every entry with a meta key that looks like this

    
    "_{$repeater_field_name}_{$row_index}_{$sub_field_name}"
    

    these needs to be renamed to

    
    "_{$repeater_field_name}_{$row_index}_{$nested_repeater_name}_0_{$sub_field_name}"
    

    On top of this you need to create a meta entry for the new repeater itself

    
    meta_key = "{$repeater_field_name}_{$row_index}_{$nested_repeater_name}"
    meta_value = 1 // this is the number of rows in the new nested repeater
    

    You will also need to create an acf field reference for the new nested repeater

    
    meta_key = "_{$repeater_field_name}_{$row_index}_{$nested_repeater_name}"
    meta_value = field_abs123 // this is the field key of the new repeater
    

    There is no simple way to do this, and I would not do this because it is unnecessary work when the issue has, what I feel, is an acceptable solution. The only reason I would do this is that a client insisted on a change of this type and then I would explain to them how to use the changes. I would not do many hours of work that is prone to errors when I could accomplish a suitable work-a-round fix in 15 minutes or less.