Wordpress:以编程方式将自定义分类添加到页面

发布于 2024-11-04 07:59:17 字数 562 浏览 6 评论 0原文

您好,我正在尝试通过表单将自定义分类术语(分层)添加到页面。我为每个术语都有一个复选框:

<input type="checkbox" name="term1" value="$taxonomy_term_id"/> 
<label for="themes" > $term_name </label>

<input type="checkbox" name="term2" value="$taxonomy_term_id2"/> 
<label for="themes" > $term_name2 </label>
[...]

提交时我使用 wp_set_object_terms 函数:

wp_set_object_terms($page_id,$_POST['term1'],$taxonomy_name,false);

但它只创建一个分类术语,其名称为 $_POST['term1'] 的值(在管理面板中,该页面没有检查新的分类术语,甚至创建了新术语 )。

有什么想法吗?

Hi i'm attempting to add custom taxonomy terms (hierarchical) to a page, via a form. I have a checkbox for each terms:

<input type="checkbox" name="term1" value="$taxonomy_term_id"/> 
<label for="themes" > $term_name </label>

<input type="checkbox" name="term2" value="$taxonomy_term_id2"/> 
<label for="themes" > $term_name2 </label>
[...]

On submit i'm using wp_set_object_terms function:

wp_set_object_terms($page_id,$_POST['term1'],$taxonomy_name,false);

but it only create a taxanomy term whose name is the value of $_POST['term1'] ( in admin panel, the page as no new taxonomy term checked, even the new term created ).

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2024-11-11 07:59:26

就是这样:

   $wpdb->insert( $wpdb->prefix .'term_relationships', array('object_id'=>$post_id, 'term_taxonomy_id'=>$_POST['term'], 'term_order'=>'0'));

This is it:

   $wpdb->insert( $wpdb->prefix .'term_relationships', array('object_id'=>$post_id, 'term_taxonomy_id'=>$_POST['term'], 'term_order'=>'0'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文