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?

  • It could be possible, but honestly, it will take a lot less time to code for than to retrofit the existing data to the new fields.

    If I had to do this I would leave the existing fields and I would add a filter to both of these fields to remove them if they have no content. Please note that you need to use the field keys and not the field names.

    
    add_filter('acf/prepare_field/key={ORIGINAL TEXT FIELD KEY HERE}", 'hide_old_fields', 20);
    add_filter('acf/prepare_field/key={ORIGINAL LINK FIELD KEY HERE}", 'hide_old_fields', 20);
    function hide_old_fields($field) {
      if (!$field['value']) {
        return false;
      }
      return $field;
    }
    

    What that does is only show the existing fields if they have a value.

    I would add the new fields. When editing the post the values can be moved to the new field and when that is done and the values are removed from the old fields they will no longer be usable.

    The next thing I would do is to alter my theme code

    
    if (have_rows('your new nested repeater name here')) {
      // new code to show new repeater
    } elseif (get_sub_field('old link field name here')) {
      // old code to show link here
    }
    

    This allows either to be used and no posts need to be updated until such time as the post is updated for some other reason, or never as the case may be.

    This will take a short time to implement as apposed to potentially hours in phpMyAdmin altering meta_keys and possible missing, breaking or anything.