Support

Account

Home Forums Backend Issues (wp-admin) Change file upload path for a specific field. Reply To: Change file upload path for a specific field.

  • For anyone out there I found the solution. This no longer exists > 'field_name_upload_prefilter'
    SO you need to change it to
    'gist_acf_upload_dir_prefilter'

    I found the solution here > https://gist.github.com/BODA82/a4b810b9c0f17fe4c52f7c7e96ade119

    Here is my code Working as of today.

    function gist_acf_upload_dir_prefilter($errors, $file, $field) {
        
        // Only allow editors and admins, change capability as you see fit
        if( !current_user_can('edit_pages') ) {
            $errors[] = 'Only Editors and Administrators may upload attachments';
        }
        
        // This filter changes directory just for item being uploaded
        add_filter('upload_dir', 'gist_acf_upload_dir');
        
    }
    
    // ACF hook, set to field key of your file upload field
    add_filter('acf/upload_prefilter/key=field_627a6567e2078', 'gist_acf_upload_dir_prefilter', 10, 3 );
    
    // Custom upload directory
    function gist_acf_upload_dir($param) {
        
        // Set to whatever directory you want the ACF file field to upload to
        $custom_dir = '/uploads/protected';
        $param['path'] = WP_CONTENT_DIR . $custom_dir;
        $param['url'] = WP_CONTENT_URL . $custom_dir;
    
        return $param;
        
    }