change_upload_dir

add_filter( 'upload_dir', 'change_upload_dir' );

function change_upload_dir( $args ) {

$id = $_REQUEST['post_id'];

if( get_post_type( $id ) == 'downloads' ) {

$args['basedir'] = wp_normalize_path( WP_CONTENT_DIR . 'downloads' );
$args['baseurl'] = content_url() . '/downloads';
$args['path'] = $args['basedir'];
$args['url'] = $args['baseurl'];
$args['subdir'] = '';

return $args;

}

}

Đọc thêm
Thu Gọn