Support

Account

Home Forums Backend Issues (wp-admin) Saved Field Data is missing after grouping

Solved

Saved Field Data is missing after grouping

  • Hey,

    I have a collection of existing fields. Now I want to use the wonderful new group fields. After moving the existing field into a group, all the saved data is missing. I think this is an ACF plugin bug? Is there a way to hold the saved user data from the fields, if I moving this into a new group?

  • I have figured out, that the field settings are saved and all is fine at the frontend. But at the backend, the fields show an empty value. For example, the image field is empty or a saved radio button selecting is set to default after grouping the existing fields. This is confusing for the user.

  • @acf-support @hube2 Without a solution, I can’t update my themes for my user. This is very very important to fix this issue. All field content or values inside a new group field will be displayed as a empty field at the backend 🙁

    I’m using ACF PRO 5.6.1 with WP 4.8.1

  • @acf-support @hube2 I’ve created a new ticket for this critical bug.

  • I really can’t help you with this, and it’s not really a but. The problem here is that you’re changing the field names. For example, if you had a field named “field_1” and you move it into a group that is named “group_1” the field’s new name is actually “group_1_field_1”. Any renaming of a field will cause the loss of data in that field. The only fix for this would be to go into the database, or to create a query, that renames all of the meta_key values and all of the acf field key references for those fields. The same thing would happen if you had a field with data in it and decided to move that field into a repeater. A group field is basically a repeater field with 1 row.

    It might be possible to do this without making db changes. Lets say that you had several fields with names like

    • hero_image
    • hero_alt
    • hero_content

    if you made a group named “hero” and then moved the three field into the group and named them

    • image
    • alt
    • content

    it’s possible that the values would be retained since the meta_keys will actually remain the same.

  • I think this isn’t a nice idea. 🙁 It’s very complicated for all developers, which using older ACF Version without grouping fields. I need a grouping layout possibility to structure the fields for the backend. Therefore I don’t need new group field names and changes of the database or template.

  • I think I misunderstood the meaning of the group fields. I thought they were designed for the structure of the backend content only.

    For example, if I using a tab field to group some of the field I don’t need any changes for the including fields and the IDs.

  • They were designed for backend organization, but ACF needs to understand that organization. For this reason the fields in the group need to be children of the the “group” field. There is no other way given how ACF creates field to associate them.

    I can understand why this might cause confusion and could be frustrating, even though I personally would not consider this a bug, but then I’m not the developer. You can always submit a support ticket and see if you can get any more input from the developer https://support.advancedcustomfields.com/new-ticket/

    If I was going to move fields around in a way that would make something break I would probably add code to make them backwards compatible. For example this will load the old value into the editor:

    
    // on admin edit screen get old value to insert into new value
    add_filter('acf/load_value/key=new_field_key', 'load_load_field_name_value', 10, 3);
    function load_load_field_name_value($value, $post_id, $field) {
      if ($value === NULL) {
        // post never saved using new field
        $value = get_field('old_field_name', $post_id, false);
      }
      return $value;
    }
    

    and then something like this in the templates where the value is used

    
    $value = get_field('old_field_name');
    if ($value === NULL) {
      // do value saved to new field
      $value = get_field('old_field_name');
    }
    // do something with value
    

    Yes, this is a little more work, but nothing that I would not expect since I’m renaming a field. Maybe this is because I deal with this type of thing often when I make changes to custom themes created by either myself or some other dev.

  • @hube2

    Thank you, but I need a solution without any changes in the database or in the templates. I won’t change any IDs or something. It must be compatible with the old field ids. So I have used the “Message Field” and I have modified it to have field like an separator / sub headline. 😉

    @acf-support

    I think a separator field with an easy headline is a good feature for the next ACF version 🙂

    ACF Field Backend

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.