I’m using Woocommerce for products. All products are imported automatically by a plugin.
Currently when i want to attach an image to a product (a post type) i have to use “Featured image” to display the image on the website. This is all manual work.
Once i save the image, the image is saved to the database in table wp_posts, the post_type is “attachment”, the post_mime_type is “image/jpeg”, the post_parent is the postID.
ID post_author post_title post_status post_name post_parent guid post_type post_mime_type
200 1 Niceimagename inherit Niceimagename 116 http://domain.com/imageurl attachment image/jpeg
What code do i have to add to my functions.php that if a post gets saved or updated that it uses the value in meta key “_image” to attach the image to the post like the sample above?
I got it now using the following code: