在执行wp\\u insert\\u post时,如何插入帖子缩略图。我尝试了下面的代码,但没有成功。
$postit = array(
\'post_title\' => $itemtitle,
\'post_content\' => \'\',
\'post_status\' => \'publish\',
\'post_type\' => \'items\',
\'post_author\' => $user_ID,
\'tags_input\' => $the_post_id,
\'post_thumbnail\' => $itemimage,
);
$the_post_idit = wp_insert_post( $postit);
任何想法,
非凡的
SO网友:Bainternet
您需要首先创建帖子并获取id:
$postit = array(
\'post_title\' => $itemtitle,
\'post_content\' => \'\',
\'post_status\' => \'publish\',
\'post_type\' => \'items\',
\'post_author\' => $user_ID,
\'tags_input\' => $the_post_id
);
$the_post_idit = wp_insert_post( $postit);
一旦你有了帖子id,你就可以使用
update_post_meta( $the_post_idit,\'_thumbnail_id\',$itemimage);
只需确保$itemimage保存附件ID即可。