个性化阅读
专注于IT技术分析

自定义帖子类型固定链接返回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)访问帖子, 我也没有成功。

我目前在网站的永久链接结构为/%year%/%postname%-将其更改为默认设置也无济于事。

有什么线索吗?我的机智到此为止。


#1


publicly_queryable需要为真, 但如果要设置public, 则可能不需要它(或exclude_from_search)。参见编解码器:http://codex.wordpress.org/Function_Reference/register_post_type#Arguments


#2


这是另一个帮助我可能遇到同样问题的人的答案…

如果你最近创建了新的CPT, 则可能需要进入”设置”>”永久链接”, 然后再次单击”保存更改”。这使所有新的重写规则都可以生效。


#3


你应该在参数中添加” _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 );
}
赞(0)
未经允许不得转载:srcmini » 自定义帖子类型固定链接返回404

评论 抢沙发

评论前必须登录!