WordPress-在另一个自定义帖子中创建自定义帖子类型的分类法?

时间:2018-11-27 09:41:09

标签: wordpress custom-post-type custom-taxonomy custom-wordpress-pages

很抱歉,如果以前已经问过这个问题,我已经尝试搜索并且无法弄清楚(对于wordpress来说是很新的)。我有一个名为Members的自定义帖子类型,以及一个名为Insights的自定义帖子类型。我希望分类显示在成员列表的见解的编辑页面中。我似乎无法填充分类法。这是到目前为止我得到的:

  bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            selectFragment(item);
            return false;
        }
    });

  private void selectFragment(MenuItem item){

    item.setChecked(true);
    int id=item.getItemId();
    switch (id){
        case R.id.nav_home: {
            loadFragment(R.id.flContent, new MainPageFragment());
            break;
        }
        case R.id.nav_my_answers: {
            if (isOnline(this)) {
                if (Config.CurrentUser != null)
                    loadFragment(R.id.flContent, new ListAnswerFragment());
                else
                    showDialog(getString(R.string.title_dialog), getString(R.string.did_not_login));
            } else {
                showDialog(getString(R.string.title_dialog), getString(R.string.no_internet));
            }
            break;
        }
        case R.id.nav_my_questions: {
            if (isOnline(this)) {
                if (Config.CurrentUser != null)
                    loadFragment(R.id.flContent, new ListQuestionFragment());
                else
                    showDialog(getString(R.string.title_dialog), getString(R.string.did_not_login));
            } else {
                showDialog(getString(R.string.title_dialog), getString(R.string.no_internet));
            }

            break;
        }
    }
}

这是我要做的工作,以将分类法添加到见解页面:

## MEMBERS ###
function post_members() {
    $labels = array(
        'name'               => _x( 'Members', 'post type general name' ),
        'singular_name'      => _x( 'Member', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'Member' ),
        'add_new_item'       => __( 'Add New Item' ),
        'edit_item'          => __( 'Edit Item' ),
        'new_item'           => __( 'New Item' ),
        'all_items'          => __( 'All Items' ),
        'view_item'          => __( 'View Item' ),
        'search_items'       => __( 'Search' ),
        'not_found'          => __( 'No items found' ),
        'not_found_in_trash' => __( 'No items found in the trash' ),
        'menu_name'          => __( 'Members' )
    );

    $args = array(
        'labels'              => $labels,
        'description'         => 'Members',
        'public'              => true,
        'supports'            => array( 'title', 'url' ),
        'menu_icon'           => 'dashicons-awards',
        'has_archive'         => false,
        'show_in_menu'        => true,
        'hierarchical'        => true,
    );
    register_post_type( 'members', $args );

}
add_action( 'init', 'post_members' );

## INSIGHTS ###
function post_insights() {
    $labels = array(
        'name'               => _x( 'Insights', 'post type general name' ),
        'singular_name'      => _x( 'Insights', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'Insights' ),
        'add_new_item'       => __( 'Add New Item' ),
        'edit_item'          => __( 'Edit Item' ),
        'new_item'           => __( 'New Item' ),
        'all_items'          => __( 'All Items' ),
        'view_item'          => __( 'View Item' ),
        'search_items'       => __( 'Search' ),
        'not_found'          => __( 'No items found' ),
        'not_found_in_trash' => __( 'No items found in the trash' ),
        'menu_name'          => __( 'Insights' )
    );

    $args = array(
        'labels'              => $labels,
        'description'         => 'Insights',
        'public'              => true,
        'supports'            => array( 'title', 'editor', 'member', 'thumbnail', 'featured' ),
        'menu_icon'           => 'dashicons-media-document',
        'has_archive'         => true,
        'show_in_menu'        => true,
        'rewrite'             => array('slug' => 'news-media/insights'),
        'taxonomies'          => array( 'members' ) ## this is what I'm trying to add
    );
    register_post_type( 'insights', $args );

}
add_action( 'init', 'post_insights' );

该框显示为ok,但未填充。

enter image description here

在旁注中,是否也可以删除“添加新类别”?

0 个答案:

没有答案