Title: Need PHP example for adding images to posts
Last modified: August 20, 2016

---

# Need PHP example for adding images to posts

 *  [superdave300](https://wordpress.org/support/users/superdave300/)
 * (@superdave300)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/need-php-example-for-adding-images-to-posts/)
 * I have a site with thousands of posts. I have a folder with hundreds of images
   in it. Each image goes with one post (not all posts have an image). Rather than
   upload each image through the UI, I want to write a PHP script to loop through
   all the images, upload them and associate them with posts. It would create the
   thumbnail as well. I figure this would be easier than manually uploading hundreds
   of photos. Does anyone have an example of uploading an image to a post? I can
   take it from there.
 * _[Bumping after less than one hour! Seriously? [No bumping](http://codex.wordpress.org/Forum_Welcome#No_Bumping).
   If it’s that urgent, consider [hiring someone](http://jobs.wordpress.net/).]_

Viewing 1 replies (of 1 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/need-php-example-for-adding-images-to-posts/#post-2630991)
 * **Stop bumping!**

Viewing 1 replies (of 1 total)

The topic ‘Need PHP example for adding images to posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/need-php-example-for-adding-images-to-posts/#post-2630991)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
