我需要过滤上传到特定文件夹的自定义帖子类型,称为“文档”,仅适用于PDF。
到目前为止,我已经:
function custom_upload_directory( $args ) {
$base_directory = \'/home/xxx/my_uploadfolder\';
$base_url = \'http://xxxx/wp-content/uploads/my_uploadfolder\';
$id = $_REQUEST[\'post_id\'];
$parent = get_post( $id )->post_parent;
// Check the post-type of the current post
if( "document" == get_post_type( $id ) || "document" == get_post_type( $parent ) ) {
$args[\'path\'] = $base_directory;
$args[\'url\'] = $base_url;
$args[\'basedir\'] = $base_directory;
$args[\'baseurl\'] = $base_url;
}
return $args;
}
add_filter( \'upload_dir\', \'custom_upload_directory\' );
它可以工作,但有一些问题::任何类型的文件都会在my\\u uploadfolder中重定向。此外,我无法从WP admin中删除这些文件。有人能帮忙吗?