我有两种自定义帖子类型的分类法。一个是类别,另一个是类型。我想限制作者能够选择两种分类法中的一种。
例如,如果作者选择其中一个"类型"分类法,他将无法选择"类别"
这可能吗?
答案 0 :(得分:1)
您只需为自定义帖子类型创建自定义分类: 这是我的工作代码。 它将仅显示自定义帖子类型的自定义分类。
// Registers the new post type and taxonomy
function wpt_packages_posttype() {
register_post_type( 'Packages',
array(
'labels' => array(
'name' => __( 'Packages' ),
'singular_name' => __( 'Packages' ),
'add_new' => __( 'Add New Packages' ),
'add_new_item' => __( 'Add New Packages' ),
'edit_item' => __( 'Edit Packages' ),
'new_item' => __( 'Add New Packages' ),
'view_item' => __( 'View Packages' ),
'search_items' => __( 'Search Packages' ),
'not_found' => __( 'No Packages found' ),
'not_found_in_trash' => __( 'No Packages found in trash' )
),
'taxonomies' => array('package-Category'),
'public' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
'capability_type' => 'post',
'rewrite' => array("slug" => "packages"), // Permalinks format
'menu_position' => 5,
)
);
}
add_action( 'init', 'wpt_packages_posttype' );
function add_console_taxonomies() {
register_taxonomy('package-Category', 'review', array(
// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Package Category', 'taxonomy general name' ),
'singular_name' => _x( 'Package Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Package Categories' ),
'all_items' => __( 'All Package Categories' ),
'parent_item' => __( 'Parent Package Category' ),
'parent_item_colon' => __( 'Parent package-Category:' ),
'edit_item' => __( 'Edit Package Category' ),
'update_item' => __( 'Update Package Category' ),
'add_new_item' => __( 'Add New Package Category' ),
'new_item_name' => __( 'New Package Category Name' ),
'menu_name' => __( 'Package Categories' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'package-Category', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/locations/"
'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
),
));
}
add_action( 'init', 'add_console_taxonomies', 0 );