Hello all,
I’m looking to rename my uploaded photos using ACF field values in the name. I can’t seem to be able to grab the values. What am I doing wrong? I’ve attached the in hope it will help.
//// RENAME FILE ON UPLOAD ////
function tecRenameImage($filename) {
$post = get_post($post_ID);
$fieldName = get_field(‘field_5c94fbc7c53c2’);
$info = pathinfo($filename);
$ext = empty($info[‘extension’]) ? ” : ‘.’ . $info[‘extension’];
//$ext = “.” . $info[‘extension’];
$name = basename($filename, $ext);
return $fieldName.’-‘.date(‘Ymd-his’).$ext;
}
add_filter(‘sanitize_file_name’, ‘tecRenameImage’, 10);