Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Download and attach image to post.
- media_sideload_image($item->image, $post_id, $item->image_caption);
- // Then find the last image added to the post attachments.
- $attachment = array_values(get_attached_media( 'image', $post_id ))[0];
- // Finally set image as the post thumbnail.
- if ($attachment) {
- set_post_thumbnail($post_id, $attachment->ID);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement