找不到wordpress中单个type.php文件的页面

时间:2013-01-08 09:40:57

标签: wordpress

我创建了自定义帖子类型'event'以在单页中显示名为single-event.php的文件,但它提供了404错误。我怎么能解决这个问题,即使我用过

  

flush_rewrite_rules();

请帮我解决我的问题......这是我的代码..

function custom_event() {
$labels = array( 
'name' => _x('Event', 'post type general name'),
'singular_name' => _x('Event', 'post type singular name'),
'add_new' => _x('Add Event', 'Content'),
'add_new_item' => __('Add New Event'),
'edit_item' => __('Edit Event'),
'new_item' => __('New Content'),
'view_item' => __('View Event'),
'search_items' => __('Search Content'),
'not_found' =>  __('Nothing found'), 
'parent_item_colon' => '',
'menu_name' => __('Event')
 );

 $args = array(
 'labels' => $labels,
 'public' => true,
 'publicly_queryable' => true,
 'show_ui' => true, 
 'show_in_menu' => true,  
 'query_var' => true,
 'rewrite' => true,
 'capability_type' => 'post',
 'has_archive' => true, 
 'hierarchical' => false,
 'menu_position' => 20,
 'supports' => array( 'title', 'editor')
  );

  flush_rewrite_rules();
  register_post_type('event', $args); 
  }
  //$wp_rewrite->flush_rules();
  //add_action('admin_init', 'flush_rewrite_rules');
   add_action ('init', 'custom_event');

1 个答案:

答案 0 :(得分:2)

尝试使用'rewrite' => array( 'slug' => 'event' )代替'rewrite' => true

此外,您不应该像这样使用flush_rewrite_rules()。它每次都会不必要地运行。您可以创建一个插件来定义自定义帖子类型,并使用register_activation_hook刷新重写规则。