I am creating posts using wp_insert_post()
, but these posts do not have featured images.
I have a post ID, and a path to the image on my server, how do I set them as the featured image?
EDIT : I added my code to publish an article. It only needs to add the thumbnail (featured image).
imagePath= ABSPATH . "wp-content\uploads\image\my_image.jpg";
publication($titre, $content, $categriesID, $tags);
function publication ($titre, $content, $categories, $tags){
$user_id = get_current_user_id();
$my_post = array(
'post_title' => $titre,
'post_content' => $content,
'post_status' => 'publish',
'post_author' => $user_id,
'post_category' => $categories,
'tags_input' => $tags
);
$post_ID = wp_insert_post( $my_post );
}
media_handle_sideload