【问题标题】:Custom Post types giving 404自定义帖子类型给出 404
【发布时间】: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 并使用您的帖子类型 slug question 进行重写),看看是否有任何改变。
  • 感谢您的回复,所有其他永久链接都有效,只是这些特定链接无效。我将尝试删除重写参数,看看是否有什么不同。
  • 删除用于重写的 slug 无效,仍然是 404。无论如何,谢谢。
  • 这很奇怪。如果我自己无法真正深入研究它,我不确定我能否提供更多帮助,可能还有其他与重写规则相冲突的东西。也许尝试使用其中一个 CPT 管理插件(Types 是我经常使用的一个)?

标签: wordpress http-status-code-404 custom-post-type permalinks


【解决方案1】:

在尝试解决此问题 3 天后,我发现它是 'hierarchical' => true 给我的错误。

只要我删除了这行代码,然后通过将永久链接设置为默认值来刷新永久链接,然后再次将它们改回来,问题就解决了。

【讨论】:

  • 如果我有一个分层的帖子类型并且我无法删除它怎么办??
【解决方案2】:

实际上,您需要在创建新的自定义帖子后更新您的永久链接,'hierarchical' => 'true' 它不会影响 404 错误。只需转到永久链接并再次保存它就可以了。

【讨论】:

  • 感谢您的建议,但当时我确实在创建新客户帖子后更新了永久链接。这没有任何区别,我设法解决此错误的唯一方法是删除 'hierarchical' => true。
猜你喜欢
  • 2016-01-22
  • 1970-01-01
  • 2012-01-01
  • 1970-01-01
  • 2011-07-24
  • 1970-01-01
  • 2015-06-07
  • 2016-06-05
  • 1970-01-01
相关资源
最近更新 更多