Home › Forums › General Issues › acf/upload_prefilter – for every field on options page › Reply To: acf/upload_prefilter – for every field on options page
Hi John,
Thanks for your input. Using your method for logging the $_POST data, this is the result:
Array
(
[name] => test.png
[action] => upload-attachment
[_wpnonce] => dee97d17e2
[_acfuploader] => field_5a856f0eb49d7
)
So, there’s nothing being sent about the origin page, just the ACF field’s key.
I guess the only and easiest way is just to create an array of all the fields (potentially only about 10, not that many in my use case). This is how I’ve solved it:
$fields = array('field_1', 'field_2', 'field_3');
foreach ($fields as $field) {
add_filter("acf/upload_prefilter/name=$field", function($errors) {
add_filter('upload_dir', function($uploads) {
$dir = '/options';
$uploads['url'] = $uploads['baseurl'] . $dir;
$uploads['path'] = $uploads['basedir'] . $dir;
return $uploads;
});
return $errors;
});
}
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.