• Resolved Shweta Danej

    (@danejshweta)


    Hello there,

    I creating a form using various ACF fields.

    For the “file” field, I want to customize the folder location for each of the file fields.

    I have 3 scenarios:

    1. Simple file upload field with name file1 – should be located to wp-content/uploads/simple-files
    2. File field with the group field – should be located to wp-content/uploads/groups
      Field Structure: Group 1 -> File 1 AND Field Path: uploads/groups/group1
      Field Structure: Group 1 -> File 1 AND Field Path: uploads/groups/group1
    3. File field with group field and the repeater field – should be located to wp-content/uploads/group-repeat
      Field Structure: Group 1-> Repeater -> File 1 AND Field Path: uploads/groups/group-repeat/repeater1/file1
      Field Structure: Group 1-> Repeater -> File 2 AND Field Path: uploads/groups/group-repeat/repeater1/file2

    Please help he understand how I can achieve this using ACF hooks.

Viewing 1 replies (of 1 total)
  • Hi there!

    ACF Support Team here, Thanks for reaching out with your query we would be happy to assist

    In order to change the upload folder, you could hook into the acf/upload_prefilter hook as shown below:

    function my_acf_upload_prefilter( $errors, $file, $field ) {
    
    add_filter('upload_dir', 'my_upload_directory');
    
    return $errors;
    
    }
    
    add_filter('acf/upload_prefilter/name=acf_field_name', 'my_acf_upload_prefilter');
    
    function my_upload_directory( $param ){
    
    $mydir = '/custom-field';
    
    $param['path'] = $param['basedir'] . $mydir;
    
    $param['url'] = $param['baseurl'] . $mydir;
    
    return $param;
    
    }

    Please have a look at a discussion at https://support.advancedcustomfields.com/forums/topic/uploaded-files-location/

    If you need further clarification, please create a ticket using our ?support form and we can look into it further.

Viewing 1 replies (of 1 total)
  • The topic ‘Upload files to custom folder using ACF file field’ is closed to new replies.