I have created an import file to get the articles from a non-wordpress db and bring them in as posts in wordpress, I am not sure how to bring over the thumbnail image into my custom field I defined as “thumbnail”. Any suggestions.
Here is the code I am using:
$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);
}
you need to get the ID back from your post insertion and use that with
add_post_meta
: