我使用下面的功能让用户从前端上传文件。它工作得很好,除了我想该文件不被附加到任何职位。目前,该文件自动附加到我用于上传的页面(mysite.com/publish)。我希望它只是单独的。
我应该在下面做些什么改变才能让它起作用?
以下是功能:
// Uploads images from the front-end
function insert_attachment($file_handler,$post_id,$setthumb=\'false\') {
// check to make sure its a successful upload
if ($_FILES[$file_handler][\'error\'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . \'/includes/image.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/file.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/media.php\');
$attach_id = media_handle_upload( $file_handler, $post_id );
if ($setthumb) update_post_meta($post_id,\'_thumbnail_id\',$attach_id);
return $attach_id;
}