2017-08-29 12 views
0

私はWordpress 4.8.1です。何らかの理由で私は、カスタムポストタイプを登録して、私が追加した場合:Wordpressはカスタムポストタイプにカテゴリを追加できません

'taxonomies' => ['category'],

それは動作しません。カスタム投稿タイプ編集画面にはカテゴリは表示されません。それはいつも前に働いたので、なぜ今はうまくいかないのか分からない。数ヶ月前にはサイトでも作業していました。誰か助けてください:)

!! 更新 !!ここ

が私のコードであり、Iは

function spanish_cpt() { 
    $labels = array(
    'name'    => _x('Spanish', 'post type general name'), 
    'singular_name'  => _x('Spanish Post', 'post type singular name'), 
    'add_new'   => _x('Add New', 'book'), 
    'add_new_item'  => __('Add New Spanish Post'), 
    'edit_item'   => __('Edit Spanish Post'), 
    'new_item'   => __('New Spanish Post'), 
    'all_items'   => __('All Spanish Posts'), 
    'view_item'   => __('View Spanish Post'), 
    'search_items'  => __('Search Spanish Posts'), 
    'not_found'   => __('No spanish posts found'), 
    'not_found_in_trash' => __('No spanish posts found in the Trash'), 
    'parent_item_colon' => '', 
    'menu_name'   => 'Spanish' 
); 
    $args = array(
    'labels'  => $labels, 
    'description' => 'Spanish version of posts', 
    'public'  => true, 
    'menu_position' => 5, 
    'supports'  => array('title', 'editor', 'thumbnail', 
          'author', 'comments', 'revisions'), 
    'has_archive' => 'es', 
    'taxonomies' => array('category', 'post_tag'), 
); 
    register_post_type('spanish', $args); 
} 
add_action('init', 'spanish_cpt'); 
+0

@silverが言ったように、コード全体を – silver

+0

として追加してください。このビットは実際には正しいので、完全なコードがないと何が間違っていると言うのは難しいです。 –

+0

@silver私のコード全体を追加しました –

答えて

0

のfunctions.php

関数register_results(){

$labels = array(
    'name' => _x('Results', 'post type general name'), 
    'singular_name' => _x('Results', 'post type singular name'), 
    'add_new' => _x('Add New', 'Results'), 
    'add_new_item' => __('Add New Case Results'), 
    'edit_item' => __('Edit Case Results'), 
    'new_item' => __('New Case Results'), 
    'all_items' => __('All Case Results'), 
    'view_item' => __('View Case Results'), 
    'search_items' => __('Search Case Results'), 
    'not_found' => __('No Results found'), 
    'not_found_in_trash' => __('No Results found in the Trash'), 
    'menu_name' => 'Case Results' 
); 
$args = array(
    'labels' => $labels, 
    'description' => 'Results and Results Related information will be hold on this', 
    'public' => true, 
    'show_in_menu' => true, 
    'menu' => 5, 
    'menu_icon'=>'dashicons-admin-post', 
    'supports' => array('title', 'editor', 'thumbnail', 'post-format', 'excerpt'), 
    'has_archive' => true, 
    'show_in_nav_menus' => true, 
    'show_ui' => true, 
    'taxonomies' => array('Category_results') 
); 
register_taxonomy(
    'Category_results', 'results', array(
    'hierarchical' => true, 
    'label' => 'Custom Category', 
    'show_admin_column' => true, 
    'show_ui' => true, 
    'query_var' => true, 
    'rewrite' => true 
)); 
register_post_type('results', $args); 

}

でこれを使用笑ことが必要であると認識します

add_action( 'init'、 'register _結果');

0

私は問題が何であるかを知りました。私は、よりきれいな方法でそれらを生成するためにカスタムポスト型ヘルパークラスを使用していました。元のコードは、この

$spanish = new CPT([ 
    'post_type_name' => 'spanish', 
    'singular' => 'Spanish Post', 
    'plural' => 'Spanish Posts', 
    'slug' => 'es' 
], [ 
    'public' => true, 
    'menu_icon' => 'dashicons-admin-post', 
    'query_var' => true, 
    'has_archive' => 'es', 
    'hierarchical' => true, 
    'can_export' => true, 
    'menu_position' => 5, 
    'publicly_queryable' => true, 
    'rewrite' => [ 
     'slug' => 'es/%spanish_categories%', 
     'with_front' => false 
    ], 
    'supports' => [ 
     'title', 'editor', 'thumbnail', 
     'author', 'comments', 'revisions', 
    ], 
    'taxonomies' => ['category'], 
]); 

だったこれは、常に取り組んできましたが、私は壊れていないと、それはもはや機能し4.8のものに更新されたとき、私は推測します。だから私はカスタムポストタイプを作成する通常の方法に切り替えて、今すぐ動作します。皆さん、ご協力とご協力をお寄せいただきありがとう

関連する問題