Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在wordpress中添加附加产品类别_Php_Mysql_Wordpress - Fatal编程技术网

Php 如何在wordpress中添加附加产品类别

Php 如何在wordpress中添加附加产品类别,php,mysql,wordpress,Php,Mysql,Wordpress,我使用下面的代码将一个产品类别添加到添加到数据库的产品中 wp_set_object_terms( $the_post_id, 528, 'product_cat' ); 它将相关的产品类别附加到该帖子中(我可以在产品页面上看到类别名称)。但当我尝试使用并提交表单时,它只创建并附加为528这样的数字(我在产品页面上看到的是528,而不是类别名称) 如果这些类别也应该在提交表单的父类别中,如何添加这些所有类别?键入强制转换值以防止其用作字符串 $kategori = $_POST['katego

我使用下面的代码将一个产品类别添加到添加到数据库的产品中

wp_set_object_terms( $the_post_id, 528, 'product_cat' );
它将相关的产品类别附加到该帖子中(我可以在产品页面上看到类别名称)。但当我尝试使用并提交表单时,它只创建并附加为528这样的数字(我在产品页面上看到的是528,而不是类别名称)


如果这些类别也应该在提交表单的父类别中,如何添加这些所有类别?

键入强制转换值以防止其用作字符串

$kategori = $_POST['kategori'];
wp_set_object_terms( $the_post_id, (int)$kategori, 'product_cat' );
至于家长类别,我不确定,虽然我认为这篇文章有你需要的。

尝试键入您的值,即(int)$kategori@kurt谢谢,它只适用于一个类别。我如何添加多个彼此为父的类别?我在下面添加了一个官方答案。如果你觉得有帮助,请接受它
$kategori = $_POST['kategori'];
wp_set_object_terms( $the_post_id, (int)$kategori, 'product_cat' );