Support

Account

Home Forums Feature Requests Change field type or group and retrieve values Reply To: Change field type or group and retrieve values

  • No, a tool does not exist to do this. If you move fields around (in or out of repeaters or group fields) or you rename them then the values already save will not be accessible.

    Altering the database to reflect any changes would be completely dependent on the exact changes made and could likely cause other things to break.

    There are paths for making these changes but there is nothing simple, and again, it would be dependent on the changes made.

    Let’s say for example that I want to do something as simple as change a field name, instead of changing the field name I would leave the old field alone and add a new field with the new name. Then I would add several filters.

    Please not that this us just an example and it may not work for your specific field, it is just a starting place.

    
    
    // use the field key of the old field
    add_filter('acf/prepare_field/key=field_XXXXX', 'hide_old_field');
    function hide_old_field($field) {
      // this prevents displaying the field so the value can no longer be edited
      // but any existing value will be preserved
      return false;
    }
    
    // load the old value when getting the new field
    add_filter(acf/load_value/name=your-new-field-name', 'load_old_value_in_new_field', 1, 3);
    function load_old_value_in_new_field($value, $post_id, $field) {
      if ($value === NULL) {
        // a value was never saved for this field
        // get the value from the old field
        $value = get_field('old_field_name', $post_id);
      }
      return $value;
    }