【发布时间】:2015-10-31 04:18:47
【问题描述】:
我正在构建我的第一个插件,它包含一个名为“功能”的自定义帖子类型 (CPT)。我正在尝试访问此 CPT 的“存档”页面,但使用除默认配置之外的任何永久链接配置时出现“错误 404”。
当我对永久链接使用“默认”配置时,返回的“存档”来自模板,而不是来自我的插件。我做错了什么?
function fmp_create_post_feature() {
register_post_type( 'feature',
array(
'labels' => array(
'name' => 'Features' ,
'singular_name' => 'Feature',
'edit_item' => __( 'Edit' ) . ' Feature',
'add_new' => __( 'Add' ) . ' nova',
'add_new_item' => __('Add').' nova Feature',
'menu_name' => 'Feature with Modal Popup',
'all_items' => 'Features',
'rewrite' => array( 'slug' => 'feature' ),
),
'public' => true,
'menu_icon' => 'dashicons-desktop',
'supports' => array(
'title',
'editor',
'thumbnail'
),
'taxonomies' => array(
'feature',
),
)
);
flush_rewrite_rules();
}
add_action( 'init', 'fmp_create_post_feature' );
上面的代码是cpt注册,下面是分类注册的代码
add_action( 'init', 'fmp_create_tax' );
function fmp_create_tax() {
register_taxonomy(
'feature',
array(
'label' => 'Feature',
'rewrite' => array( 'slug' => 'feature' ),
'hierarchical' => true,
)
);
}
【问题讨论】:
标签: wordpress custom-post-type archive permalinks