I know there are a lot of posts about it, but I don’t want to upload a URL image to the library, I already have the image in the library and its IP. How can I use it with wp_insert_post
?
1 Answer
You can use the function set_post_thubmnail()
.
After you inserted your post, just call this one, and you are ready to go.
$yourpostid = wp_insert_post( $args ); // Define the post in the args first
set_post_thumbnail( $yourpostid, $thumbnail_id ); // set the ID of your thumbnail to be the featured image of your newly created post.