可能使用set_post_thumbnail()
? (Codex ref.)
EDIT
要使用Post ID获取附件ID,请执行以下操作:
// Associative array of attachments, as $attachment_id => $attachment
$attachments = get_children( array(\'post_parent\' => $post->ID, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => \'ASC\', \'orderby\' => \'menu_order ID\') );
$attachment = $attachments[0]; // ID of your single, attached image.
然后将其设置为特色图像:
set_post_thumbnail( $attachment );
我必须检查以确定;文档有点混乱。默认输出可能是对象。不管
get_children()
会让你找到你的单独附件的ID,给出帖子ID。