Support

Account

Home Forums Feature Requests Read-Only Field Reply To: Read-Only Field

  • I had the same problem with a disabled post_object field: its value is lost on save.

    Ended with this workaround:

    
    add_filter('acf/update_value/name=companies', function ($value, $user_id, $field, $original) {
        //debug
        //error_log('Saving companies: ' . json_encode($value) . ' ' . $user_id);
        //error_log('Last value: ' . get_field('companies', $user_id));
    
        /*
         * Workaround for read only field where its value is reset
         * on the edit profile screen to ''.
         *
         * We set its value always to an array [] (empty or with companies).
         */
        if ($value === '') {
            $value = get_field('companies', $user_id);
        }
    
        return $value;
    }, 10, 4);
    

    Quite a hack but it works now fine.