カスタム投稿タイプに固有のカスタム分類法
1 回答
- 投票
つまりカスタム投稿タイプのカスタム分類法MY_NEW_CARSS
を登録します:
$my_taxon_name = 'MY_NEW_CARSS';
$my_post_types = array('SUB_CAT_1','SUB_CAT_2','SUB_CAT_3');
//REGISTER CUSTOM TAXONOMY ( http://codex.wordpress.org/Function_Reference/register_taxonomy )
//If you aim to register HIERARCHICAL(Parent-ed) post type, read this warning: https://codex.wordpress.org/Function_Reference/register_post_type#hierarchical
add_action( 'init', 'my_f32' ); function my_f32() {
register_taxonomy( $GLOBALS['my_taxon_name'], array(),
array(
'label'=>$GLOBALS['my_taxon_name'], 'public'=>true, 'show_ui'=>true, 'show_admin_column'=>true, 'query_var'=>true,
'hierarchical'=>true, 'rewrite'=>array('with_front'=>true,'hierarchical'=>true),
));
}
//REGISTER CUSTOM POST TYPE ( http://codex.wordpress.org/Function_Reference/register_post_type )
add_action( 'init', 'myf_63' );function myf_63() {
foreach ($GLOBALS['my_post_types'] as $each_Type) {
register_post_type( $each_Type,
array(
'label'=>$each_Type, 'labels' => array('name'=>$each_Type.' pagess', 'singular_name'=>$each_Type.' page'), 'public' => true, 'publicly_queryable'=> true, 'show_ui'=>true, 'capability_type' => 'post', 'has_archive' => true, 'query_var'=> true, 'can_export' => true, //'exclude_from_search' => false, 'show_in_nav_menus' => true, 'show_in_menu' => 'edit.php?post_type=page',//true, 'menu_position' => 5,
'hierarchical' =>true,
'supports' =>array( 'page-attributes', 'title', 'editor', 'thumbnail' ),
'rewrite' => array('with_front'=>true, ), // 'rewrite' => array("ep_mask"=>EP_PERMALINK ...) OR 'permalink_epmask'=>EP_PERMALINK,
));
register_taxonomy_for_object_type('category',$each_Type); //standard categories
register_taxonomy_for_object_type($GLOBALS['my_taxon_name'] ,$each_Type); //Custom categories
}
}
i.e. register a custom taxonomy MY_NEW_CARSS
for custom post types:
$my_taxon_name = 'MY_NEW_CARSS';
$my_post_types = array('SUB_CAT_1','SUB_CAT_2','SUB_CAT_3');
//REGISTER CUSTOM TAXONOMY ( http://codex.wordpress.org/Function_Reference/register_taxonomy )
//If you aim to register HIERARCHICAL(Parent-ed) post type, read this warning: https://codex.wordpress.org/Function_Reference/register_post_type#hierarchical
add_action( 'init', 'my_f32' ); function my_f32() {
register_taxonomy( $GLOBALS['my_taxon_name'], array(),
array(
'label'=>$GLOBALS['my_taxon_name'], 'public'=>true, 'show_ui'=>true, 'show_admin_column'=>true, 'query_var'=>true,
'hierarchical'=>true, 'rewrite'=>array('with_front'=>true,'hierarchical'=>true),
));
}
//REGISTER CUSTOM POST TYPE ( http://codex.wordpress.org/Function_Reference/register_post_type )
add_action( 'init', 'myf_63' );function myf_63() {
foreach ($GLOBALS['my_post_types'] as $each_Type) {
register_post_type( $each_Type,
array(
'label'=>$each_Type, 'labels' => array('name'=>$each_Type.' pagess', 'singular_name'=>$each_Type.' page'), 'public' => true, 'publicly_queryable'=> true, 'show_ui'=>true, 'capability_type' => 'post', 'has_archive' => true, 'query_var'=> true, 'can_export' => true, //'exclude_from_search' => false, 'show_in_nav_menus' => true, 'show_in_menu' => 'edit.php?post_type=page',//true, 'menu_position' => 5,
'hierarchical' =>true,
'supports' =>array( 'page-attributes', 'title', 'editor', 'thumbnail' ),
'rewrite' => array('with_front'=>true, ), // 'rewrite' => array("ep_mask"=>EP_PERMALINK ...) OR 'permalink_epmask'=>EP_PERMALINK,
));
register_taxonomy_for_object_type('category',$each_Type); //standard categories
register_taxonomy_for_object_type($GLOBALS['my_taxon_name'] ,$each_Type); //Custom categories
}
}
カテゴリがデフォルトの投稿(/%category%/%postname%/パーマリンク構造に基づいて)と同じように動作するように、投稿タイプと同様に動作するカスタム分類法を作成して、カスタムの投稿を作成したい投稿タイプは次のように表示されます www.example.com/custom-post-type/custom-taxonomy-name/post-name また、カテゴリメタボックスは、新しいデフォルトの投稿を追加するときにのみ表示され、カスタム投稿タイプに新しい投稿を追加するときは表示されません.カスタム分類ボックスは、新しい投稿を追加するときにのみ表示されます.新しいデフォルトの投稿を追加するときではなく、カスタム投稿タイプで.