Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible while adding post through wp_insert_post also upload images to this post from url.

share|improve this question
    
yes via, wp_insert_attachment –  Wyck Jan 5 '13 at 21:51
    
@Wyck but file isn't uploaded - it just sets given url. –  user1692333 Jan 5 '13 at 22:03
    
You need to show code on WPSE if you want a real answer. –  Wyck Jan 5 '13 at 22:53

1 Answer 1

up vote 0 down vote accepted

You can attach images to a post from URI via the media_sideload_image function:

$post = array(); // your post data
$post_id = wp_insert_post( $post );
$url = "http://s.wordpress.org/style/images/wp3-logo.png";
$desc = "The WordPress Logo";
$image = media_sideload_image( $url, $post_id, $desc );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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