我已经创建了一个导入文件,从非wordpress数据库获取文章,并将其作为wordpress中的帖子引入,我不知道如何将缩略图图像引入我定义为“缩略图”的自定义字段。任何建议。
以下是我使用的代码:
$results = mysql_query("SELECT headline, abstract, article, author, posted, category, img, facilities FROM articles",$lclink);
$i = 0;
while ($row = mysql_fetch_array($results,MYSQL_ASSOC)) {
$post = array();
$post[\'post_status\'] = \'publish\';
$post[\'post_category\'] = array(1);
$post[\'post_date\'] = date(\'Y-m-d H:i:s\',strtotime($row[\'posted\']));
$post[\'post_title\'] = $row[\'headline\'];
$post[\'post_excerpt\'] = $row[\'abstract\'];
$post[\'post_content\'] = $row[\'article\'];
$post[\'post_author\'] = $row[\'author\'];
$posts[$i] = $post;
$i++;
}
require(\'./wp-load.php\');
foreach ($posts as $post) {
wp_insert_post($post);
}