2017-08-04 50 views
1

我正在使用Redux Framework創建一個自定義帖子類型。直接按類別創建類別和類別視圖,並直接轉到鏈接,但該鏈接應直接轉到404頁面。請檢查下面的代碼,並讓我知道我的代碼中有什麼錯誤。分類頁面轉到404 pgae

remove_action('init', 'brightness_service_register',10); 
add_action('init', 'brightness_service_register',1); 
function brightness_service_register() 
{ 
$labels = array(
'name' => __('Service', 'brightness'), 
'add_new' => __('Add New', 'brightness'), 
'add_new_item' => __('Add New Service', 'brightness'), 
'edit_item' => __('Edit Service', 'brightness'), 
'new_item' => __('New Service', 'brightness'), 
'view_item' => __('View Service', 'brightness'), 
'search_items' => __('Search Service', 'brightness'), 
'not_found' => __('No items found', 'brightness'), 
'not_found_in_trash' => __('No items found in Trash', 'brightness'), 
'parent_item_colon' => '', 
'menu_name' => 'Service' 
); 
$args = array(
'labels' => $labels, 
'menu_icon' => 'dashicons-images-alt2', 
'public' => true, 
'publicly_queryable' => true, 
'show_ui' => true, 
'show_in_menu' => true, 
'query_var' => true, 
'capability_type' => 'post', 
'has_archive' => true, 
'hierarchical' => false, 
'rewrite' => array('slug' => 'service', 'with_front' => false), 
'exclude_from_search' => true, 
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes' 
)); 
$taxonomy_labels = array(
    'name' => __('Service Categories', 'taxonomy general name'), 
    'singular_name' => __('Service Category', 'taxonomy singular name'), 
    'search_items' => __('Search Category'), 
    'all_items' => __('All Service Categories'), 
    'parent_item' => __('Parent Service Category'), 
    'parent_item_colon' => __('Parent Location:'), 
    'edit_item' => __('Edit Category'), 
    'update_item' => __('Update Category'), 
    'add_new_item' => __('Add New Category'), 
    'new_item_name' => __('New Category Name'), 
    'menu_name' => __('Service Categories'), 
); 
$taxonomy_args = array(
'hierarchical' => true, 
'labels' => $taxonomy_labels, 
'rewrite' => array(
    'slug' => 'service-categories', // 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/"),); 
register_post_type('service' , $args); 
register_taxonomy('coll-categories', 'service',$taxonomy_args); 
} 
+0

你是說,當你查看這些類別中,直接到404頁拍攝? –

+0

是的,請檢查我的代碼是否有錯誤? @AmitJoshi – Vishit

回答

0

Basead WordPress的抄本時,需要用戶register_taxonomy_for_object_type到inteconnect自定義文章類型和自定義分類,以be sage than sorry。所以我認爲在撥打register_taxonomy後添加此行可能會爲您解決此問題。

register_taxonomy_for_object_type('coll-categories', 'service'); 
+0

register_taxonomy_for_object_type('coll-categories','service'); 類別提交已在我的自定義帖子類型中刪除。 – Vishit

0

以及你所做的一切都是正確的,當我在你需要結束您的數組$ taxonomy_args

你的答案 您可以註冊您的自定義分類後添加flush_rewrite_rules()陣列粘貼您的代碼塊。

注意:只在激活或取消激活時或者當您知道需要更改重寫規則時刷新規則。不要在任何會以例行方式觸發的鉤子上執行此操作。在WP工程師的文章的評論更多詳細信息:自定義文章類型和永久

OR

你可以去設置→永久鏈接→保存永久鏈接,應手動刷新重寫規則。

參考從 https://wordpress.stackexchange.com/questions/250222/custom-taxonomy-leads-to-404-page

+0

不能使用此代碼。 – Vishit

+0

我已經使它工作夥計,你需要創建taxonomy.php來查看 – sagar

0
add_action('init', 'brightness_service_register',0); 
function brightness_service_register() 
{ 

$labels = array(
'name' => __('Service', 'brightness'), 
'add_new' => __('Add New', 'brightness'), 
'add_new_item' => __('Add New Service', 'brightness'), 

    'edit_item' => __('Edit Service', 'brightness'), 
    'new_item' => __('New Service', 'brightness'), 
    'view_item' => __('View Service', 'brightness'), 
    'search_items' => __('Search Service', 'brightness'), 
    'not_found' => __('No items found', 'brightness'), 
    'not_found_in_trash' => __('No items found in Trash', 'brightness'), 
    'parent_item_colon' => '', 
    'menu_name' => 'Service' 
); 
$args = array(
    'labels' => $labels, 
    'menu_icon' => 'dashicons-images-alt2', 
    'public' => true, 
    'publicly_queryable' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true, 
    'capability_type' => 'post', 
    'has_archive' => true, 
    'hierarchical' => false, 
    'rewrite' => array('slug' => 'service'), 
    'exclude_from_search' => true, 
    'supports' => array('title', 'editor', 'thumbnail', 'page-attributes' 
)); 
$taxonomy_labels = array(
     'name' => __('Service Categories', 'taxonomy general name'), 
     'singular_name' => __('Service Category', 'taxonomy singular name'), 
     'search_items' => __('Search Category'), 
     'all_items' => __('All Service Categories'), 
     'parent_item' => __('Parent Service Category'), 
     'parent_item_colon' => __('Parent Location:'), 
     'edit_item' => __('Edit Category'), 
     'update_item' => __('Update Category'), 
     'add_new_item' => __('Add New Category'), 
     'new_item_name' => __('New Category Name'), 
     'menu_name' => __('Service Categories'), 
    ); 
$taxonomy_args = array(
    'labels' => $taxonomy_labels, 
    'hierarchical'   => true, 
    'show_ui'    => true, 
    'show_admin_column'  => true, 
    'query_var'    => true, 
    'rewrite' => array('slug' => 'service-categories', 'with_front' => false) 
); 
register_post_type('service' , $args); 
register_taxonomy('service-categories', 'service',$taxonomy_args); 
flush_rewrite_rules(); 

}

+0

你能告訴爲什麼添加taxonomy.php文件在我的主題? – Vishit

+0

taxonomy.php將顯示我所測試的所有術語..它運行良好所有這些類別中的文章類型需要顯示so taxonomy.php使用 – sagar

+0

並且我在taxonomy.php文件中添加了archive.php代碼直接轉到404頁面但在它正在工作的文件中添加了一些打印。請解釋一下。 – Vishit