用以下物品撞击砖墙:
我有:
调用了1个自定义帖子类型cpt_community
调用了自定义分类法tax_community
如果我设置\'rewrite\' => true
在我的CPT注册中,该CPT条目的永久链接形式为http://<domain>/cpt_community/test_item/
, 当我浏览到它时,我得到了一个404。
如果我设置\'rewrite\' => false
, 那么permalinks是http://<domain>/?cpt_community=test_item/
, 这个很好用。
所以,很明显我做错了/很愚蠢-问题是,什么?
[更新]
每次更改后,我都会通过进入设置>永久链接(并保存)刷新规则。在将所有内容都保持一个小时后,一切都开始正常工作了。为什么会延迟
Code
CPT注册
function community_post_type() {
$labels = array(\'name\' => \'Community\');
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => false,
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'has_archive\' => true,
\'supports\' => array(\'title\',\'editor\',\'excerpt\',\'custom-fields\',\'comments\',\'revisions\',\'thumbnail\',\'author\',\'page-attributes\')
);
register_post_type(\'cpt_community\', $args);
}
add_action( \'init\', \'community_post_type\' );
自定义分类注册
function community_tax_type() {
register_taxonomy(
\'tax_community\',
\'cpt_community\',
array( \'hierarchical\' => false,
\'label\' => \'Community Content Type\',
\'show_ui\' => true,\'query_var\' => true,
\'rewrite\' => true,
\'singular_label\' => \'Community Content Type\',
\'capabilities\' => array(\'assign_terms\' => \'edit_community_tags\')
)
);
# allow roles to add community taxonomy tags to a community CPT
$roles = array("subscriber","contributor","author","editor","administrator");
foreach ($roles as $role_name) {
$role = get_role($role_name);
$role->add_cap("edit_community_tags");
}
}
add_action( \'init\', \'community_tax_type\' );