嗨,我從前端上傳文件,但現在的代碼只獲取圖像附件ID我想要的圖像url。從前端上傳圖片,並獲得其網址
function agp_process_woofile($file, $post_id){
if ($_FILES[$file]['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');
$attachment_id = media_handle_upload($file, $post_id);
add_post_meta($post_id, '_file_paths', $attachment_id);
$attachment_data = array(
'ID' => $attachment_id,
'post_excerpt' => $caption
);
wp_update_post($attachment_data);
return $attachment_id;
}
見attachment_id我想從這個函數獲取URL和更新網址爲 「_file_paths」 後元
是否正確$ attachment_id = media_handle_upload($ file,$ post_id); $ attachment_url = wp_get_attachment_url($ attachment_id); add_post_meta($ post_id,'_file_paths',$ attachment_url); – Corlax
你自己寫代碼了嗎?沒有代碼可以在代碼中獲取附件URL。 –