Solution:
You would need to use 2 filter to change directly for your custom post to handle uploads.
Change YOUR_CPT
and YOUR_DIR
to your desired directory
According to DOCS
When you upload Media from your WordPress admin dashboard, wp_handle_upload is called once for each file the user specified. wp_handle_upload_prefilter is an admin filter that is called by the wp_handle_upload function. The single parameter, $file, represent a single element of the $_FILES array. The wp_handle_upload_prefilter provides you with an opportunity to examine or alter the filename before the file is moved to its final location.
AND upload_dir
This hook allows you to change the directory where files are uploaded to. The keys and values in the array are used by the wp_upload_dir function in wordpress core, which is doing the work.
Code to use:
add_filter( 'wp_handle_upload_prefilter', 'my_pre_upload' );
function my_pre_upload( $file ) {
add_filter( 'upload_dir', 'my_custom_upload_dir' );
return $file;
}
function my_custom_upload_dir( $param ) {
$id = $_REQUEST['post_id'];
$parent = get_post( $id )->post_parent;
if( "YOUR_CPT" == get_post_type( $id ) || "YOUR_CPT" == get_post_type( $parent ) ) {
$mydir = '/YOUR_DIR';
$param['path'] = $param['basedir'] . $mydir;
$param['url'] = $param['baseurl'] . $mydir;
}
return $param;
}
Also you can read about this article