2017-08-29 211 views
0

我在WordPress的4.8.1。出於某種原因,當我註冊自定義類型後,我補充一下:WordPress的不能添加類別自定義帖子類型

'taxonomies' => ['category'],

它不工作。類別不會顯示在自定義帖子類型編輯屏幕上。它一直在工作,所以我不明白爲什麼現在不行。它幾個月前甚至在網站上工作。有人幫助:)

!! UPDATE !!

這裏是我的代碼,我意識到這是必要的笑

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

+0

@silver說,顯示你的整個代碼。這一點實際上是正確的,沒有完整的代碼很難說出什麼問題。 –

+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 _results');

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出問題了,它不再起作用。所以我只是轉向創建自定義帖子類型的常規方式,它現在可以工作。感謝大家的幫助和參與。

相關問題