我正在開發一個網站,用戶可以通過它更新爲發佈縮略圖來捕獲他/她的圖片(通過.getusermedia)。爲特色圖片添加用戶元
的問題是,後縮略圖獲取所有用戶更新 - 我想後縮略圖,只對特定用戶
function Generate_Featured_Image($filename, $parent_post_id ){
require('/wp-load.php');
$filetype = wp_check_filetype(basename($filename), null);
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $filename),
'post_mime_type' => $filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename( $filename)),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
wp_update_attachment_metadata($attach_id, $attach_data);
//add_user_meta($current_user_id, $parent_post_id, $attach_id);
set_post_thumbnail($parent_post_id, $attach_id);
}
的script.php
Generate_Featured_Image($addroot.$current_user_id.$extimage, 88 );
// addroot=path ext-extension(.jpg) (this is name of file saved)
我試圖更新用戶add_user_meta完成任務,但甚至無法啓動
UPDATE
<?php
// $filename is succesfully saved as currentuserid+.jpg.
$addroot = '/wp-content/uploads/2016/09/';
$current_user_id = get_current_user_id();
$extimage = '.jpg';
$filename = $addroot.$current_user_id.$extimage;
$filetype = wp_check_filetype(basename($filename), null);
// Get the path to the upload directory.
$wp_upload_dir = wp_upload_dir();
// Prepare an array of post data for the attachment.
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename($filename),
'post_mime_type' => $filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_status' => 'inherit'
);
// Insert the attachment.
$attach_id = wp_insert_attachment($attachment, $filename, 0);
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Generate the metadata for the attachment, and update the database record.
$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
wp_update_attachment_metadata($attach_id, $attach_data);
update_user_meta(get_the_ID(), $filename , $_POST[ $filename ]);
?>
如何從usermeta由$ attach_id調用圖像進一步進行,並displayinf用戶爲thumbnail-摸不清這一步
是POS噸縮略圖應該更新一個和每個用戶相同?爲什麼將它設置爲發佈縮略圖而不是某個用戶元字段? –
是的帖子是相同的,即所有用戶的帖子ID相同。我只是想爲不同的用戶提供不同的特色圖片(由他們上傳) –