谢谢你的回答。这很对劲。我现在使用以下代码:
//SAVE THE POST - $new_post is my array that conforms to the necessary requirements
$pid = wp_insert_post($new_post);
//SET MY TAGS UP PROPERLY - $tagsArray contains an array of tags
wp_set_post_tags($pid, $tagsArray);
//ADD IMAGE TO IMAGE-GALLERY AND return $image_id - $wp_image is my image filename
$wp_filetype = wp_check_filetype(basename($wp_image), null);
$attachment = array(
\'post_mime_type\' => $wp_filetype[\'type\'],
\'post_title\' => preg_replace(\'/\\.[^.]+$/\', \'\', $myImageTitle),
\'post_content\' => \'\',
\'post_status\' => \'inherit\'
);
$serverFullPath = \'/home/user/public_html/mysite/wp-content/uploads/\';
$image_id = wp_insert_attachment($attachment, $serverFullPath . $wp_image, $pid);
//ADD THE MEDIA GALLERY IMAGE AS A FEATURED IMAGE FOR THIS POST
update_post_meta($pid, "_thumbnail_id", $image_id);
//POST THE POST
do_action(\'wp_insert_post\', \'wp_insert_post\');
我查看了媒体库,我的图像就在那里:)虽然它没有指定文件的作者,但与其他显示“admin”的图像不同。
谢谢你的帮助。