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
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀