是的,这是可能的,WordPress没有API,但有一些有用的函数。
我会将所有行加载到数组中,如下所示
$your_table = [\'post_id\' => \'image\', \'post_id\' => \'image\', …]
然后执行foreach循环
foreach($your_table as $post_id => $image)
{
//full path to the image
$image_path = _YOUR_FULL_ABSOLUTE_PATH.$image;
/**
* Get an ID of the inserted attachment
* This takes care of resizing image and stuff…
* The fourth param I would sugest you to keep true, since in case of duplicate entry in your table, it will not have been inserted more than once
*/
$featured_image = wp_insert_attachment(array(\'attachment_meta\'), $image_path, $post_id, true);
//assign featured image
add_post_meta($post_id, \'_thumbnail_id\', $featured_image);
}
“attachment\\u meta”研究
here