• Asked you guys before, but thought id give it another shot!

    Im trying to change the path in which images are uploaded through my ACF custom field. I was able to add a folder within the “/wp-content/uploads” folder and upload to that, but what i really want is to redirect the upload path to a folder outside “uploads”. Is it possible to change the ‘basedir’ and ‘baseurl’ to something like “/wp-content/stuff/uploaded_stuff” for example? Below is the function im currently using to redirect the specific ACF uploader.

    add_filter(‘acf/upload_prefilter/name=custom_field_name', 'field_name_upload_prefilter');
    function field_name_upload_prefilter($errors) {
      // in this filter we add a WP filter that alters the upload path
      add_filter('upload_dir', 'field_name_upload_dir');
      return $errors;
    }
    // second filter
    function field_name_upload_dir($uploads) {
      // here is where we later the path
      $uploads['path'] = $uploads[‘basedir’].’/unique_upload_folder’;
      $uploads['url'] = $uploads['baseurl'].'/unique_upload_folder';
      $uploads['subdir'] = '';
      return $uploads;
    }

    Thanks in advance!

    – Charlie

    https://www.ads-software.com/plugins/advanced-custom-fields/

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Changing file upload directory for custom field’ is closed to new replies.