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 a 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 to manually use 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 so开发者_C百科mething different? I was originally going to use custom fields till I realized a custom field can only have one value and I needed two values: imageurl and imagetitle for each image. So it seems programatically creating a post type of attachment for each image is the best way to go. yes?
I look forward to anyone's response to help in this matter.
Not an expert on serialization for wordpress but have you checked the wordpress php function maybe_serialize
精彩评论