Guest User

Untitled

a guest
Feb 23rd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1.  
  2. Following is code i use to insert images.
  3. [code]
  4. foreach ( $extra_images as $extra_image )
  5. {
  6. // Download file to temp location
  7. $tmp2 = download_url( $extra_image ) ;
  8.  
  9. // fix file name for query strings
  10.  
  11. preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $extra_image, $matches) ;
  12.  
  13. $file_array2['name'] = basename( $matches[0] ) ;
  14.  
  15. $file_array2['tmp_name'] = $tmp2 ;
  16.  
  17. $imgID = media_handle_sideload( $file_array2 , $post_id , 'desc' );
  18.  
  19. $imagearray[] = $imgID ;
  20.  
  21. }
  22.  
  23. $imgids = implode(' , ', $imagearray ) ;
  24.  
  25. $result = update_post_meta( $post_id, '_product_image_gallery', $imgids ) ;
  26. [/code]
Add Comment
Please, Sign In to add comment