2011-05-04 76 views
1

從拖網支持論壇和博客我看到除了我自己以外的公平的少數人在自定義帖子類型和永久鏈接上遇到困難。自定義的帖子類型返回404

我的自定義帖子類型(日記)註冊成功,並且管理端的所有內容都顯示正常。如果您在前端搜索它,它會顯示在搜索結果中。但是,當我點擊進入日記文章時,我收到了404。

我的代碼:

register_post_type('diary_post', 
    array(
    'labels' => array(
     'name' => __('Diary Post'), 
     'singular_name' => __('Diary Post'), 
     'add_new' => _x('Add New'), 
     'add_new_item' => __('Add New Diary Post'), 
     'edit_item' => __('Edit Diary Post'), 
     'new_item' => __('New Diary Post'), 
     'view_item' => __('View Diary Post'), 
     'search_items' => __('Search Diary Posts'), 
     'not_found' => __('No Diary posts found'), 
     'not_found_in_trash' => __('No Diary posts found in Trash'), 
     'parent_item_colon' => '' 
    ), 
    'description' => __('Posts to appear on the Diary page'), 
    'public' => true, 
    'publicly_queryable' => false, 
    'exclude_from_search' => false, 
    'query_var' => true, 
    'menu_position' => 4, 
    'supports' => array('title','editor','author','excerpt','thumbnail', 'custom-fields','comments','trackbacks','revisions'), 
    'taxonomies' => array('diary_post_type','post_tag'), 
    'has_archive' => true, 
    'rewrite' => array('slug' => 'diary','with_front' => false) 
) 
); 

我試圖從各個崗位下列建議的解決方案沒有任何成功:

  • 節省再我的永久鏈接更改
  • 「改寫」只是「真'
  • 'with_front'=> false和
  • 'with_front'=> true將
  • flush_rewrite_rules();後
  • register_post_type
  • 檢查有沒有名爲「日記」

即使我嘗試通過默認的永久鏈接結構,如http://localhost/?diary_post=my-title-here我沒有成功訪問帖子頁或帖子。

該網站的我的永久鏈接結構目前是/%year%/%postname% - 將其更改爲默認設置也無濟於事。

任何線索?在我的智慧結束在這裏。

+0

有時,再次保存固定鏈接也可以解決問題。 – 2014-01-11 18:20:48

回答

0

您應該爲參數添加「_builtin」屬性。

function rw_portfolio_register(){ 
    $args = array(
     'label' => __('Portfolio'), 
     'singular_label' => __('Portfolio'), 
     'public' => true, 
     'show_ui' => true, 
     '_builtin' => false, 
     'capability_type' => 'post', 
     'hierarchical' => false, 
     'rewrite' => array("slug" => "project"), 
     'supports' => array('title', 'editor')//Boxes will be showed in the panel 
     ); 

    register_post_type('rw_portfolio' , $args); 
} 
2

這裏是另一種答案,幫助像我一樣,可能也有同樣問題的人......

如果您最近創建了新的CPT,你可能需要進入設置>固定鏈接並再次點擊保存更改。這允許任何新的重寫規則生效。

相關問題