Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. // Download and attach image to post.
  2. media_sideload_image($item->image, $post_id, $item->image_caption);
  3.  
  4. // Then find the last image added to the post attachments.
  5. $attachment = array_values(get_attached_media( 'image', $post_id ))[0];
  6.  
  7. // Finally set image as the post thumbnail.
  8. if ($attachment) {
  9. set_post_thumbnail($post_id, $attachment->ID);
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement