我有一个自定义贴子“艺术家”和一个分类/类别“艺术家类别”,我想创建(通过开发)一个新贴子并设置艺术家的类别,但它不起作用。
我用以下代码对其进行了测试:
function createNewPost( $response ){
    global $userMeta;
    $userID = $response->ID;
    $user = new WP_User( $userID );
    $role = $userMeta->getUserRole();
    //$catId = get_cat_ID("dj");
    if( $role = \'artiste\' ){ 
        $newPost = array(
          \'post_title\'    => $user->nickname, 
          \'post_content\'  => $user->description,
          \'post_status\'   => \'pending\',
          \'post_author\'   => $userID,
          \'post_type\'     => \'cpt_artists\',
          \'tax_input\' => array(\'artist-category\' => array(\'dj\')
        ));
        $post_id = wp_insert_post( $newPost );
        wp_set_post_terms( $post_id, array( \'dj\'), \'artist-category\');
    }
}
 但它不起作用。
对于测试,我列出了wordpress的所有分类法,结果是:
类别、post\\u标记、nav\\u菜单、link\\u类别、post\\u格式
为什么这里没有列出我的自定义分类法“艺术家类别”?