donglie7778 2019-04-22 21:09
浏览 71
已采纳

register_taxonomy不会创建用户分类

Trying to create a set of user taxonomies with no result. Error log is empty. The code works for custom post types, but when I set it to create user taxobomy- nothing happens. Not sure where this went wrong.

add_action( 'init', 'user_status_taxonomy' );
function user_status_taxonomy() {
 register_taxonomy(
    'profession', 'user',
     array(
        'public' => true,
        'labels' => array(
            'name' => __( 'Professions' ),
            'singular_name' => __( 'Profession' ),
            'menu_name' => __( 'Professions' ),
            'search_items' => __( 'Search Professions' ),
            'popular_items' => __( 'Popular Professions' ),
            'all_items' => __( 'All Professions' ),
            'edit_item' => __( 'Edit Profession' ),
            'update_item' => __( 'Update Profession' ),
            'add_new_item' => __( 'Add New Profession' ),
            'new_item_name' => __( 'New Profession Name' ),
            'separate_items_with_commas' => __( 'Separate professions with commas' ),
            'add_or_remove_items' => __( 'Add or remove professions' ),
            'choose_from_most_used' => __( 'Choose from the most popular professions' ),
        )
    )
);
}
  • 写回答

1条回答 默认 最新

  • dongzhashou0116 2019-04-22 21:35
    关注

    You will need to add the category page to the admin menu. The function above is simply registering the taxonomy. Not displaying it anywhere until its called upon.

    add_action( 'admin_menu', 'add_user_categories_to_admin' );
    
    function add_user_categories_to_admin() {
        $taxonomy = get_taxonomy('profession');
        add_users_page(
            esc_attr( $taxonomy->labels->menu_name ),//The Page Title
            esc_attr( $taxonomy->labels->menu_name ),//The Menu Title
            $taxonomy->cap->manage_terms, // Taxonomy Capabilities
            'edit-tags.php?taxonomy=' . $taxonomy->name // The Slug
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果