为什么我在wordpress中的自定义帖子没有显示?

Cla*_*ire 1 wordpress

我创建了一个帖子,然后它说我已经发布但是当我点击网址时,我找不到一个页面!

这是我的自定义帖子设置代码:

add_action('init', 'offered_register');
function offered_register() {

$labels = array(
    'name' => _x('Offered items'),
    'singular_name' => _x('Item'),
    'add_new' => _x('Give an item away'),
    'add_new_item' => __('Give a new item away'),
    'edit_item' => __('Edit item'),
    'new_item' => __('Give Item Away'),
    'view_item' => __('View Item'),
    'search_items' => __('Search Offered Items'),
    'not_found' =>  __('Nothing found'),
    'not_found_in_trash' => __('Nothing found in Trash'),
    'parent_item_colon' => ''
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'menu_icon' => get_stylesheet_directory_uri() . '/images/article16.png',
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title','thumbnail', 'custom-fields','comments')
  ); 

register_post_type( 'offered' , $args );
}
Run Code Online (Sandbox Code Playgroud)

gra*_*etc 5

你的register_post_type()功能看起来很好.我猜你已经启用了很多永久链接.访问"设置">"永久链接"页面,然后重试.

然后阅读: 刷新重写插件激活规则

问题是,当注册新的帖子类型时,WordPress用来处理相当永久链接的重写规则不会自动重新生成. flush_rewrite_rules()必须调用以获取新的帖子类型重写.这通常以两种方式完成:

  1. 如果您正在使用插件,请添加flush_rewrite_rules()到插件激活挂钩回调(请参阅上面的链接)
  2. 访问设置>永久链接页面,该页面需要flush_rewrite_rules()

什么你不想做的就是调用flush_rewrite_rules()init回调-这是不是你想要的东西呼吁每一个页面请求.