【发布时间】:2013-05-10 04:56:14
【问题描述】:
现在我知道这已经涵盖了很多,但我在这里阅读了以前的修复并没有任何运气。
基本上,我的问题自定义帖子类型给了我 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);
}
【问题讨论】:
-
是否有任何类型的“漂亮的永久链接”有效,或者是 CPT 特有的问题?如果所有漂亮的永久链接都损坏了,您可能需要在 Apache 配置中启用
mod_rewrite。 -
另外,尝试简单地从
$args中删除rewrite参数(它将默认为 true 并使用您的帖子类型 slugquestion进行重写),看看是否有任何改变。 -
感谢您的回复,所有其他永久链接都有效,只是这些特定链接无效。我将尝试删除重写参数,看看是否有什么不同。
-
删除用于重写的 slug 无效,仍然是 404。无论如何,谢谢。
-
这很奇怪。如果我自己无法真正深入研究它,我不确定我能否提供更多帮助,可能还有其他与重写规则相冲突的东西。也许尝试使用其中一个 CPT 管理插件(Types 是我经常使用的一个)?
标签: wordpress http-status-code-404 custom-post-type permalinks