我在woocmmerce中编写了一个脚本来导入1000个简单的产品我的脚本运行良好,它在我的wordpress网站上添加了所有产品,但是这些产品没有显示在前端商店中。当我打开单个产品时,它会显示带有价格的产品,但当我搜索类别时,它不会显示
当我编辑产品并通过单击“更新”按钮从“管理”面板进行更新时,没有更改任何内容,然后产品显示在我的商店中,我无法找出问题所在,请帮助注意1。我已经尝试过删除瞬态,因此它不起作用
这是我的密码
$querystr = "SELECT * FROM `table_name`";$pageposts = $wpdb->get_results($querystr, OBJECT);
foreach($pageposts as $productpost) {
$post = array(
\'post_title\' => $productpost->attribute,
\'post_excerpt\' => \'<pre> \'.$productpost->porduct_name."<br/>".$productpost->description.\' <pre>\',
\'post_status\' => "publish",
\'post_content\' => \'test\',
\'post_name\' => $productpost->attribute, //name/slug
\'post_type\' => "product"
);
$new_post_id = wp_insert_post( $post);
wp_set_object_terms ($new_post_id,\'simple\',\'product_type\');
wp_set_object_terms( $new_post_id, 2321, \'product_cat\');
update_post_meta( $new_post_id, \'_stock_status\', \'instock\');
update_post_meta( $new_post_id, \'_weight\', "0.06" );
update_post_meta( $new_post_id, \'_sku\', $productpost->sku);
update_post_meta( $new_post_id, \'_stock\', "100" );
update_post_meta($new_post_id, \'_regular_price\', (float)$productprice);
update_post_meta($new_post_id, \'_price\', (float)$productprice);
update_post_meta($new_post_id,\'_meta_key\',\'_visiblity\');
require_once(ABSPATH . \'wp-admin/includes/media.php\');
require_once(ABSPATH . \'wp-admin/includes/file.php\');
require_once(ABSPATH . \'wp-admin/includes/image.php\');
$thumb_url = "image_path.jpg";
if (@getimagesize($thumb_url)) {
$tmp = download_url( $thumb_url );
preg_match(\'/[^\\?]+\\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/\', $thumb_url, $matches);
$file_array[\'name\'] = basename($matches[0]);
$file_array[\'tmp_name\'] = $tmp;
if ( is_wp_error( $tmp ) ) {
@unlink($file_array[\'tmp_name\']);
$file_array[\'tmp_name\'] = \'\';
$logtxt .= "Error: download_url error - $tmp\\n";
}else{
$logtxt .= "download_url: $tmp\\n";
}
//use media_handle_sideload to upload img:
$thumbid = media_handle_sideload( $file_array, $new_post_id, \'gallery desc\' );
// If error storing permanently, unlink
if ( is_wp_error($thumbid) ) {
@unlink($file_array[\'tmp_name\']);
//return $thumbid;
$logtxt .= "Error: media_handle_sideload error - $thumbid\\n";
}else{
$logtxt .= "ThumbID: $thumbid\\n";
set_post_thumbnail($new_post_id, $thumbid);
}
}
update_post_meta( $new_post_id, \'_visibility\', \'visible\' );
update_post_meta($new_post_id, \'post_status\', \'publish\');