这里提出的解决方案可以让我轻松了WordPress邮寄打造“分类”:如何以编程方式设置新Woocommerce产品创建的类别?
//Check if category already exists
$cat_ID = get_cat_ID($category);
//If it doesn't exist create new category
if($cat_ID == 0) {
$cat_name = array('cat_name' => $category);
wp_insert_category($cat_name);
}
//Get ID of category again incase a new one has been created
$new_cat_ID = get_cat_ID($category);
// Create post object
$new_post = array(
'post_title' => $headline,
'post_content' => $body,
'post_excerpt' => $excerpt,
'post_date' => $date,
'post_date_gmt' => $date,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array($new_cat_ID)
);
// Insert the post into the database
wp_insert_post($new_post);
然而,Woocommerce不承认这些类别。 Woocommerce类别存储在其他地方。如何以编程方式为woocommerce创建类别,以及将其分配给新帖子的正确方法是什么?
如何添加'product_cat'本身? – 2017-05-19 18:53:56