WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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.