2017-04-05 125 views

回答

0

提供你有term_id是爲了你們的類別(即與get_term_by),你可以這樣做:

wp_set_object_terms($post_id, [$category->term_id, $sub_category->term_id], 'product_cat'); 
0

您需要的產品ID添加到表term_relationships。爲此,您需要從「term_taxonomy」表中獲得「term_taxonomy_id」。

因此,在term_relationships中,object_id =從term_taxonomy表中找到的product_ID和term_taxonomy_id。

您可以通過這種方式爲產品分配任何類別/子類別。

相關問題