Home Forums Backend Issues (wp-admin) Programmatically updating Local JSON? Reply To: Programmatically updating Local JSON?

  • updating the json file is something that is only triggered by acf when you hit save when working on a field group. It might be possible for you to trigger this, but I have a feeling that it will create an infinite loop if called inside of an acf/load_field filter.

    // get the field group the field is in
    $field_group = acf_get_field_group($group_key);
    // get the fields in the field group
    // this is where an infinite loop may happen
    // may be able to stop this by removing your acf/load_field filter
    $field_group['fields'] = acf_get_fields( $field_group );
    // write the json file
    acf_write_json_field_group( $field_group );

    even if this works, more than likely this will turn on the “sync” of the field group since this will not alter the field group in the database, only the json file.

    On a side note, I generally only generate the choices for a select field, or do other dynamic changes to a field when the field is not being edited in the acf field group editor. The reason is that I like my fields to be in their original state without modifications.

    // general acf/load_field filter
    function my_acf_load_field_filter($field) {
      global $post;
      if ($post && isset($post->ID) && get_post_type($post->ID) == 'acf-field-group') {
        // do not change when editing field group
        return $field;

    Another reason for not doing what you want to do is that there’s really no point in leaving the acf/load_field filter in place if you’re going to change the actual field in ACF. The purpose of the filter is to alter the field based on something that may be constantly changing and it really does not make much sense, at least not to me, to actually make permanent changes to the field every time it’s loaded. I think that you’ll find this will cause a drop in performance if you are constantly saving a new .json file or updating the field in the database every time it’s loaded.