Adding Featured Image to Post programatically
For each image/post combination, run the following. $image_name is the filename, $post_id is the post ID. if( $image_name != ” && !has_post_thumbnail( $post_id ) ){ $base = get_stylesheet_directory(); $imgfile= $base . ‘/import/’ . $image_name; // Images are stored inside an imports folder, in the theme directory $filename = basename($imgfile); $upload_file = wp_upload_bits($filename, null, file_get_contents($imgfile)); if … Read more