1

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?

  • Henry, please always provide your research in your questions. And please don't use the generic php tag. Nearly everything is about PHP somehow on this site. Thanks. – kaiser Feb 3 '14 at 14:11
  • Oh, sorry, I really didn't want to bother you. I was used to stackoverflow, where the php tag is useful. I'll make better questions in the future. Thank you. – Feel The Noise Feb 3 '14 at 14:46
3

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.
  • Thank you so much! It works like a charm. Thank you for helping me again. – Feel The Noise Feb 3 '14 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.