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

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

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码