1

我今天早上刚更新到 WordPress 3.7,我开始在我的一种自定义帖子类型上收到 404 错误。我正在通过一个插件实现多个 CPT。除了一个之外,所有其他 CPT 都很好。

相同的代码如下:

// 注册作者帖子类型

function custom_post_author() {
 $labels = array(
'name' => 'Authors',
'singular_name' => 'Author',
    'add_new' => 'Add New',
    'add_new_item' => 'Add New Author',
    'edit_item' => 'Edit Author',
    'new_item' => 'New Author',
    'all_items' => 'All Authors',
    'view_item' => 'View Author',
    'search_items' => 'Search Authors',
    'not_found' =>  'No authors found',
    'not_found_in_trash' => 'No authors found in Trash',
    'parent_item_colon' => '',
    'menu_name' => 'Authors'
  );

  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'authors' ),
    'capability_type' => 'post',
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => null,
    'menu_icon' => plugins_url( 'images/authors.png', dirname( __FILE__ )),
    'supports' => array( 'title', 'thumbnail', 'comments')
  );

  register_post_type( 'author', $args );
}
add_action( 'init', 'custom_post_author' );

CPT 在后端是可见的,但是当我在前端查看任何帖子时,它会给出 404。关于如何解决它的任何建议?

4

3 回答 3

3

似乎 WordPress 3.7 不喜欢将自定义帖子类型定义为author. 将其更改authors为工作正常。但是,这也需要在 wp_posts 表中进行更新。

于 2013-10-25T08:48:21.947 回答
2

I had a very similar error: I could not go to any singular page of my custom post types. Updating the permalink settings did not help me either. I debugged a little bit and found out that somehow the rewrites for my custom post types had not been set in the $wp_rewrite->rewrite_rules() array.

All my custom post types are registered within a plugin. Then I remembered that I once read in the documentation that you would have to flush the rules on plugin activation/deactivation (see http://codex.wordpress.org/Function_Reference/flush_rewrite_rules).

So, I fixed my issue by adding flush_rewrite_rules() to the function that registers all my custom post types and I think it will help you too!

function register_my_custom_post_types()
{
  register_post_type( ... );

  // flush the rewrite_rules after registering the post types
  flush_rewrite_rules();
}
于 2013-10-25T19:17:31.003 回答
1

我使用以下步骤解决了这个问题:

WordPress从的菜单转到 paramlink 页面Settings->paramlinks并通过单击保存更改来更新设置(不需要更改任何设置)(或者您可能不需要更新设置,只访问paramlinks页面就足够了)然后尝试查看您的自定义帖子。它会出现。

于 2013-10-25T08:29:15.637 回答