Home › Forums › Backend Issues (wp-admin) › Change file upload path for one specific field. › Reply To: Change file upload path for one specific field.
I can’t get this to direct images to a folder…
add_filter('acf/upload_prefilter/name=field_6140aa779827d', 'field_name_upload_prefilter');
function field_nameupload_prefilter($errors) {
echo '<pre>Hello world 1</pre>';
// in this filter we add a WP filter that alters the upload path
add_filter('upload_dir', 'field_name_upload_dir');
echo '<pre>Hello world 2</pre>';
return $errors;
}
// second filter
function field_name_upload_dir($uploads) {
// here is where we later the path
$uploads['path'] = $uploads['basedir'].'/companies';
$uploads['url'] = $uploads['baseurl'].'/companies';
$uploads['subdir'] = 'logos';
echo '<pre>Hello world 4</pre>';
return $uploads;
}
Field type is Image, name “Company Logo” (“companylogo”, “field_6140aa779827d”).
Aim is to upload a company logo but siphon it to a child of “uploads
” – “uploads/companies/logos
“.
But it continues going to “uploads/2021/09
“.
None of my “Hello world
” test lines are displayed, which may suggest the filter isn’t firing at all (?).
Any thoughts?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.