1

现在我知道这已经被覆盖了很多,但我已经阅读了以前的修复,并没有任何运气。自定义帖子类型给出404

基本上我的问题的自定义帖子类型给我404错误。

到目前为止,我已经试过如下:

  • 设置固定链接为默认值,然后再回到更改它们。
  • 在register_post_type之前添加flush_rewrite_rules。
  • 我检查过,没有相同名称的页面和帖子。
  • 删除并重新创建htaccess文件。
  • 添加'rewrite'=> array('slug'=>'question','with_front'=> FALSE)
  • 创建自定义的永久链接结构。

代码如下:

add_action('init', 'irt_questions_create'); 

function irt_questions_create() { 

$labels = array(
    'name' => _x('Questions', 'post type general name', 'your_text_domain'), 
    'singular_name' => _x('Question', 'post type singular name', 'your_text_domain'), 
    'add_new' => _x('Add New', 'Question', 'your_text_domain'), 
    'add_new_item' => __('Add New Question', 'your_text_domain'), 
    'edit_item' => __('Edit Question', 'your_text_domain'), 
    'new_item' => __('New Question', 'your_text_domain'), 
    'all_items' => __('All Questions', 'your_text_domain'), 
    'view_item' => __('View Question', 'your_text_domain'), 
    'search_items' => __('Search Questions', 'your_text_domain'), 
    'not_found' => __('No Questions found', 'your_text_domain'), 
    'not_found_in_trash' => __('No Questions found in Trash', 'your_text_domain'), 
    'parent_item_colon' => '', 
    'menu_name' => __('Questions', 'your_text_domain') 
); 

$args = array(
    'labels' => $labels, 
    'public' => true, 
    'publicly_queryable' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true, 
    'rewrite' => array('slug' => _x('module', 'URL slug', 'your_text_domain')), 
    'capability_type' => 'post', 
    'has_archive' => true, 
    'hierarchical' => true, 
    'menu_position' => 106, 
    'supports' => array('title', 'editor', /*'author',*/ 'thumbnail', /*'excerpt', 'comments', 'custom-fields', 'revisions',*/ 'page-attributes') 
); 
register_post_type('question', $args); 

} 
+0

做任何类型的“漂亮的固定链接”的工作,或者是特定于CPT的问题?如果所有漂亮的固定链接都被破坏了,那么你可能需要在你的Apache配置中启用'mod_rewrite'。 – Ennui

+0

另外,试着简单地从'$ args'中删除'rewrite'参数(它将默认为true,并使用你的post type slug'question来重写)并查看是否改变了任何内容。 – Ennui

+0

感谢您的回复,所有其他永久链接工作其只是这些不特定的。我会尝试删除重写参数,看看是否有任何区别。 – Mark

回答

5

3天后的试图解决这一问题,我发现了它是“分层” =>真给我的错误。

只要我删除了这行代码,然后刷新固定链接通过设置永久链接默认,然后再次更改它们返回问题修复。

+0

如果我有一个分层的帖子类型,我不能删除? –

2

在实际中,您需要在创建新的自定义帖子后更新您的固定链接,'hierarchical' => 'true'它不会影响404错误。只要去固定链接,并再次保存,使其流动。

+0

感谢您的建议,但当时我在创建新客户帖子后更新了固定链接。这没有任何区别,我设法解决这个错误的唯一方法是删除'hierarchical'=> true。 – Mark