Wordpress 4.1:自定义文章类型获胜';t加载,链接don';不起作用


Wordpress 4.1: Custom Post Type won't load, links don't work

我已经注册了一个自定义的帖子类型:

<?php
register_post_type( 'my_cpt_fiction',
  array(
    'labels' => array(
        'name' => __( 'Custom Posts' )
      , 'singular_name' => __( 'Custom Post' )
      , 'add_new' => 'Add New'
      , 'add_new_item' => 'Create a new Custom Post'
      , 'edit' => 'Edit Custom Post'
      , 'edit_item' => 'Edit Custom Post'
      , 'new_item' => 'Create a new Custom Post,'
      , 'view_item' => 'View Custom Post,'
      , 'search_items' => 'Search Custom Post'
      , 'not_found' => 'No Custom Posts found'
      , 'not_found_in_trash' => 'No Custom Posts found in trash'
    ),
      'public' => true
    , 'has_archive' => true
    , 'supports' => Array(
        'title' => 'title'
      , 'editor' => 'editor'
      , 'author' => 'author'
      , 'comments' => 'comments'
    )
    , 'show_ui'             => true
    , 'rewrite' => array( 'slug' =>  'my_custom_post' , 'with_front' => false, 'feeds' => true )
    , 'capability_type'    => array('my_custom_post','my_custom_posts')
    , 'map_meta_cap'        => true
    , 'taxonomies' => array('category')
    , 'publicly_queryable'  => true
    , 'exclude_from_search' => false
    , 'query_var'          => true
  )
);

我没有分类法。

这个添加到菜单中,我可以创建和编辑。但当我访问自定义帖子的链接时,它并没有加载,而是看到了主静态主页。

我尝试过很多不同的永久链接组合,或者没有永久链接。

我似乎也找不到任何关于具体显示自定义帖子类型的信息,就好像这是一篇帖子或页面一样,人们只是认为它一定有效。。。

如有任何帮助,我们将不胜感激。

/J

由于WordPress重写规则,这种情况大多数时候都会发生,它们存储在数据库中,您需要刷新它们。

转到设置-永久链接,只需单击保存即可启动刷新重写规则。

尝试将其包装在init钩子中:

add_action( 'init', 'create_my_post_type' );
function create_my_post_type() {
    // Your code here
}

创建帖子类型或更改其重写设置后,转到wordpress设置->永久链接并单击保存。这将重置重写规则并重新创建.htaccess文件。