Title: Manually Attatch Images to Post using SQL
Last modified: August 20, 2016

---

# Manually Attatch Images to Post using SQL

 *  [jesselrye](https://wordpress.org/support/users/jesselrye/)
 * (@jesselrye)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/manually-attatch-images-to-post-using-sql/)
 * I have created a custom post type called products and need to associate multiple
   images with one product. The actual data already exists in a different non-wordpress
   database in table called productimages that simply has a productid, imageurl,
   and image title. i need to convert this data into wordpress format so wordpress
   can display everything i need. this is something that will be done regularly 
   using sql automatically deleting products and meta data related and re-adding
   from our main database which changes regularly.
 * From what I can tell the best way to make this work is manually using sql to 
   insert the productimages as attachment posts just like wordpress does when you
   upload media to wordpress. then to associate the image with a product i have 
   to manually insert records into postmeta but the data in postmeta is serialized
   or something and i am unsure how i would insert the data in the correct serialize
   format using mysql. is it even possible to do this with mysql?
 * am i going about this wrong should i be doing something different? i was originally
   going to use custom fields till i realized a custom field can only have one value
   and i need two values a imageurl, and image title for each image so it seems 
   programatically creating a post type of attachment for each image was the best
   way to go. yes?
 * I look forward to anyones response to help in this matter.

The topic ‘Manually Attatch Images to Post using SQL’ is closed to new replies.

## Tags

 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [jesselrye](https://wordpress.org/support/users/jesselrye/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/manually-attatch-images-to-post-using-sql/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
