遵循这种方法:
$product_information = array(
'post_author' => wp_get_current_user()->ID,
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_type' => 'product',
'post_status' => 'pending'
);
$product_id = wp_insert_post( $product_information );
wp_set_object_terms($product_id, array('Economy'), 'product_cat');
我设置了product_cat分类法,当创建产品时,我收到邮件: “您好!供应商(UserTest)添加了一个新产品,等待审查。”
现在,我尝试了一种类似的方法,以在WP后端面板的“供应商”列中插入供应商名称,但是我缺少了一些东西。
我希望在关联数组中添加post_author
键是解决方案,但是我错了。
我尝试使用:
wp_set_object_terms($product_id, wp_get_current_user()->ID , 'taxonomy-wcpv_product_vendors');
但是什么也没发生。我想念的是什么?
答案 0 :(得分:0)
我用过:
wp_set_object_terms( $product_id, WC_Product_Vendors_Utils::get_logged_in_vendor(), WC_PRODUCT_VENDORS_TAXONOMY );