Advertisement
Guest User

Untitled

a guest
May 26th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. $image_data = file_get_contents($thumbnail);
  2. $filename = basename($thumbnail);
  3.  
  4. file_put_contents($thumbnail, $image_data);
  5.  
  6. $wp_filetype = wp_check_filetype($filename, null );
  7. $attachment = array(
  8. 'post_mime_type' => $wp_filetype['type'],
  9. 'post_title' => sanitize_file_name($filename),
  10. 'post_content' => '',
  11. 'post_status' => 'inherit'
  12. );
  13. $attach_id = wp_insert_attachment( $attachment, $thumbnail, $postId );
  14. require_once(ABSPATH . 'wp-admin/includes/image.php');
  15. $attach_data = wp_generate_attachment_metadata( $attach_id, $thumbnail );
  16. $res1= wp_update_attachment_metadata( $attach_id, $attach_data );
  17. update_post_meta( $postId, '_thumbnail_id', $attach_id );
  18.  
  19. <img width="350" height="421" src="http://localhost/w/wp-content/uploads/https://1.bp.blogspot.com/-yL4P2_f5ygk/Vxx2SBGRrII/AAAAAAAANL0/pfK0uEWrRTwZuJoq0UuwxNHpXMQ4ouypQCLcB/s1600/Step%2BUp%2BRevolution%2B2012%2BDual%2BAudio%2BHindi%2BBluRay.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Step2BUp2BRevolution2B20122BDual2BAudio2BHindi2BBluRay.jpg" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement