我想添加产品属性(wc\\u create\\u attribute)(&;通过函数分配的术语(wp\\U insert\\U term)。php。
示例:
$args = array(
\'name\' => "Color",
\'slug\' => "color",
\'order_by\' => "menu_order",
\'has_archives\' => "",
);
wc_create_attribute($args);
$add = wp_insert_term( "Blue", \'pa_color\', array( \'slug\' => "blue" ) );
print_r($add);
The
wc_create_attribute()
工作正常,但当
wp_insert_term()
运行时,它会因“分类无效”而引发错误。当我重新加载页面时,它工作正常,因为这样分类法就不再无效了。看来
wp_insert_term()
以某种方式在create\\u属性之前执行。我不明白为什么一次尝试都不行。
也许你能帮我
SO网友:Andrii Kovalenko
Try to reregister taxonomies
$args = array(
\'name\' => "Color",
\'slug\' => "color",
\'order_by\' => "menu_order",
\'has_archives\' => "",
);
wc_create_attribute($args);
WC_Post_Types::register_taxonomies();
$add = wp_insert_term( "Blue", \'pa_color\', array( \'slug\' => "blue" ) );
print_r($add);