答案 0 :(得分:0)
将此添加到functions.php文件
function create_post_types() {
register_post_type('myPostType',
array(
'labels' => array(
'name' => __( 'My post types' ),
'singular_name' => __( 'My post type' )
),
'taxonomies' => array('category'), //this is the 'magic' one
'public' => true,
'show_ui' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor' )
)
);
}
add_action( 'init', 'create_post_types' );
修改强>
如果您只想在编辑器中显示自定义帖子类型类别,请考虑在ACF中使用自定义字段:http://www.advancedcustomfields.com/
或者您添加自己的分类法类型: https://wordpress.stackexchange.com/questions/57493/custom-taxonomy-specific-to-a-custom-post-type
function themes_taxonomy() {
register_taxonomy(
'themes_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'themes', //post type name
array(
'hierarchical' => true,
'label' => 'Themes store', //Display name
'query_var' => true,
'rewrite' => array(
'slug' => 'themes', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action( 'init', 'themes_taxonomy');
虽然没有试过那个
答案 1 :(得分:0)
您需要做的就是,在注册自定义分类时,您可以指定它所属的邮政类型。像这样:
add_action('init', 'product_tags', 0);
function product_tags() {
$labels = array(
'name' => _x( 'Product Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Product Tag', 'taxonomy singular name' ),
'menu_name' => __( 'Product Tags' )
// etc...
);
$args = array(
'hierarchical' => false,
'public' => true,
'show_in_nav_menus' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array(
'slug' => 'product-tag',
'with_front' => true,
'hierarchical' => true
),
);
// 'products' is the name of the Custom Post Type, ensuring that it will not pop up under any other post types.
register_taxonomy( 'product_tags', 'products', $args );
}