我需要在哪个数据库表和列中插入图像路径,以便在wp admin中显示产品图像(不在前端)?我在WordPress中通过查询插入产品,而不是通过管理员插入产品。
$insert = $wpdb->insert( $prefix."posts", array(
"post_title" => $posTitle,
"post_content" => $postContent,
"post_status" => "publish",
"post_type" => "product"
) );
// select products ID
$select = $wpdb->get_results( "SELECT ID AS productsId
FROM " . $prefix . "posts
WHERE post_title=\'" . $posTitle . "\'" );
// echo $select[0]->productsId; die();
// insert umage in posts and product attribute meta posts table
$insertImg = $wpdb->insert( $prefix . "posts", array(
"post_status" => "inherit",
"post_type" => "attachment",
"guid" => $postGuid,
"post_parent" => $select[0]->productsId
) );
SO网友:Zarar Ansari
$image_url = $review[\'image\'];
$tmp = download_url( $image_url );
preg_match(\'/[^\\?]+\\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/\', $image_url, $matches);
$file_array[\'name\'] = basename($matches[0]);
$file_array[\'tmp_name\'] = $tmp;
$thumbid = media_handle_sideload( $file_array, $new_post_id, \'gallery desc\' );
set_post_thumbnail($new_post_id, $thumbid);
update_post_meta( $new_post_id, \'_product_image_gallery\', $thumb_url);