这可能不是最优雅的方式(我不确定是否允许覆盖$\\u全局文件),但这似乎是可行的:
global $post;
if ($_FILES) {
$files = $_FILES[\'upload_attachment\'];
foreach ($files[\'name\'] as $key => $value) {
if ($files[\'name\'][$key]) {
$file = array(
\'name\' => $files[\'name\'][$key],
\'type\' => $files[\'type\'][$key],
\'tmp_name\' => $files[\'tmp_name\'][$key],
\'error\' => $files[\'error\'][$key],
\'size\' => $files[\'size\'][$key]
);
$_FILES = array("upload_attachment" => $file);
foreach ($_FILES as $file => $array) {
$newupload = wp_insert_attachment($file,$post->ID);
}
}
}
}