管理上的自定义帖子类型类别

时间:2016-05-07 作者:Erdinç Taze

我已经创建了名为“视频”的自定义帖子类型,并添加了类别支持。问题是,当我转到自定义帖子类型的类别时,它也会显示普通帖子的类别。

我想把他们分开我怎么才能解决这个问题?

<小时>

My custom-post-type code:

add_action( \'init\', \'register_cpt_video\' );

function register_cpt_video() {

    $labels = array(
        \'name\' => __( \'Videolar\', \'video\' ),
        \'singular_name\' => __( \'Video\', \'video\' ),
        \'add_new\' => __( \'Yeni Video Ekle\', \'video\' ),
        \'add_new_item\' => __( \'Yeni Video Ekle\', \'video\' ),
        \'edit_item\' => __( \'Video Düzenle\', \'video\' ),
        \'new_item\' => __( \'Yeni Video\', \'video\' ),
        \'view_item\' => __( \'Video Görüntüle\', \'video\' ),
        \'search_items\' => __( \'Video Arama\', \'video\' ),
        \'not_found\' => __( \'Herhangi bir video bulunamadı\', \'video\' ),
        \'not_found_in_trash\' => __( \'Herhangi bir video bulunmadı\', \'video\' ),
        \'parent_item_colon\' => __( \'Ebeveyn Video\', \'video\' ),
        \'menu_name\' => __( \'Videolar\', \'video\' ),
    );

    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => false,
        \'description\' => \'Video Galeri içeriklerinizi buradan giriniz.\',
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => \'dashicons-video-alt2\',
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => false,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( \'video\', $args );
}

1 个回复
SO网友:N00b

您在参数中添加了以下行:\'taxonomies\' => array( \'category\', \'post_tag\' ),. 它会将相同的类别和标记注册到video 用于默认帖子的帖子类型。

第一件事:删除行\'taxonomies\' => array( \'category\', \'post_tag\' ),

为了只对video post类型,则需要注册新的分类法。这应该是相同的.php 如果新帖子类型仅限于video 岗位类型。这不是强制性的,但对将来的维护更好。

我添加了一些我通常指定的参数。查看所有可能的参数here. Read the whole document to get what you actually need. 其中一些论点极大地改变了这种行为。

// Video categories
add_action( \'init\', \'register_taxonomy_video_category\', 0 );

function register_taxonomy_video_category() {

    $labels = array(
        // See list of labels in docs I linked above (bold and blue "here")     
    );


    $args = array(  

        // Custom labels? Remove them all to get "default"
        \'labels\'              => $labels,
        // Does these have child-parent relationships?
        \'hierarchical\'        => true,
        // Translatable pretty slugs?
        \'rewrite\'             => array( \'slug\' => __( \'video-category\', \'video\' ) ),
        // Generate a default UI for managing this taxonomy?
        \'show_ui\'             => true,
        // Allow automatic creation of taxonomy columns on associated post-types table?
        \'show_admin_column\'   => true,
        // Show in quick edit panel?
        \'show_in_quick_edit\'  => false
        )  
    );

    // "video-category" is the name of the taxonomy
    // "video" is the post type you want it to use with
    register_taxonomy( \'video-category\', \'video\', $args );
}
<小时>

相关推荐