在WP前端,我为用户创建了一个上传表单。
该表单有三个输入字段(标题、标记和上载)。
所以我想补充一下“Title - Tag - file_name“作为alt
文件上载期间图像的属性。
我如何处理下面的代码?
if ($gui == \'upload\') {
if (!function_exists(\'wp_generate_attachment_metadata\')){
require_once(ABSPATH . "wp-admin" . \'/includes/image.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/file.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/media.php\');
}
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file][\'error\'] !== UPLOAD_ERR_OK) {
return "Upload Err: " . $_FILES[$file][\'error\'];
}
$attach_id = media_handle_upload( $file, $newPost );
}
}
if ($attach_id > 0){
//and if you want to set that image as Post then use:
update_post_meta($newPost,\'Uploaded_Image_ID\',$attach_id);
}
}