现在我知道这已经涵盖了很多,但我已经阅读了以前的修复,并没有任何运气 .
基本上我的问题的自定义帖子类型给我404错误 .
到目前为止,我已经尝试了以下内容:
-
将永久链接设置为默认值,然后再将其更改回来 .
-
在register_post_type之前添加flush_rewrite_rules .
-
我已经检查过,并且没有相同名称的页面和帖子 .
-
删除并重新创建了htaccess文件 .
-
添加'rewrite' =>数组('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);
}
2 回答
在尝试修复此问题3天后,我发现它是 'hierarchical' => true 给了我错误 .
一旦我删除了这行代码,然后通过将永久链接设置为默认值来刷新永久链接,然后再将其更改回来问题已修复 .
在“实际”中,您需要在创建新的自定义帖子后更新永久链接,
'hierarchical' => 'true'
它不会影响404错误 . 只是去永久链接并再次保存它使它成为流动 .