dongmangji0950 2015-11-13 22:30
浏览 82
已采纳

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

I use below code to add one product category to a product which is added database;

wp_set_object_terms( $the_post_id, 528, 'product_cat' );

and it appends the relevant product category to that post (I can see the category name on products page). But when I tried to do it with and submit form, it only creates and appends as number like 528 (I see the 528 on product page instead of category name);

$kategori = $_POST['kategori'];
wp_set_object_terms( $the_post_id, $kategori, 'product_cat' );

How can I add these all categories if it should be in parent categories also with a submit form?

  • 写回答

1条回答 默认 最新

  • dtf0925 2015-11-13 23:04
    关注

    Type cast your value to prevent it being used as a string.

    $kategori = $_POST['kategori'];
    wp_set_object_terms( $the_post_id, (int)$kategori, 'product_cat' );
    

    As to parent categories im not sure although I think this post has what you need. https://wordpress.stackexchange.com/questions/99681/how-to-set-hierarchical-terms-to-a-post-using-wp-set-object-terms

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制