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.