如何为自定义帖子分配多个taxonmoy?

时间:2017-09-28 07:42:26

标签: wordpress

我正在努力从前端创建自定义帖子。帖子值正确插入,但当我尝试为此帖子分配自定义分类法时,它不起作用,并且没有在管理员中显示指定的分类术语。我曾多次这样做,但没有得到什么问题。我试图破坏这些值,并尝试分配一个分类术语。但是没有成功。这是我的代码,用于分配自定义分类术语

$id = wp_insert_post(array('post_title'=>$title, 'post_type'=>'associations', 'post_content'=>$generalDesc,'post_status'=>'publish'));
foreach($associationIndustry as $industry)
{   
    wp_set_post_terms($id, $industry, 'industries', true); 

} 

1 个答案:

答案 0 :(得分:1)

尝试使用以下代码:

代替39和52设置您的类别ID

如果您的$associationIndustry具有相同的数组,则可以直接传递该变量而不使用foreach循环

// the number is category ID
wp_set_post_terms( $id, array( 39 , 52 ), 'industries' );