Support

Account

Home Forums Feature Requests Hook – Save Post by Group Reply To: Hook – Save Post by Group

  • As far as I know ACF never looks at the group a field is in when saving. ACF does not save field in group order. It looks at $_POST['acf'][$field_key] at the top level and works through the array, recursing into sub arrays.

    The field group that each field is in is not part of the submitted data.

    Finding the real group key could be potentially problematic. Take for example a field that is cloned. If you look at the parent and recurse up you will get to the group that the field lives in before being cloned. The only way to get to the field from the group that it is cloned into is to recurse over fields and sub fields starting at the top. This is provided by the recursive nature of the input

    
    $_POST['acf']['field_XXXXX'][0]['field_YYYYY'][0]['field_ZZZZZ'][etc]
    
    

    in order to provide this hook ACF would need to, at the top level, record the group key of that field and then refer to that when saving each field. There could be multiple groups being saved so ACF would need to have a hook for every field. Also do to the recursive nature there isn’t any way to know at what level the loop over fields is being done. Instead of reading the inputs sequentially ACF would need to first read through them, sort them by group and then loop over the fields in each group. Or the hierarchy of the submitted data would need to be altered to something like
    $_POS['acf'][$group_key][0][$field_key] which would result in completely breaking backwards compatibility. And even here there would be an issue with cloned fields I think.

    I do know what you are talking about, every acf/save_post action I create has something at the top that checks the passed $post_id value against something before it does anything and returns if it’s not what it needs to be. But knowing how ACF looks at the submitted fields I don’t see how anything else could be possible.