我在wordpress中创建自己的帖子但是我遇到了一些问题,我不确定如何修复它。
以下register_post_type会创建无效的帖子类型错误。
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'talent',
array(
'labels' => array(
'name' => __( 'Talent' ),
'singular_name' => __( 'talent' )
),
'public' => true,
'has_archive' => true,
)
);
}
它似乎不喜欢人才这个词。如果我改变人才'到了'arist'有用。然而,它需要是“才能”。用于URL。我已经检查过wordpress并且使用人才不应该导致与默认的wordpress设置冲突。
答案 0 :(得分:3)
这确实很奇怪,我尝试了你的片段,它按预期工作。这让我想到你可能已经尝试通过另一种方法注册相同的帖子类型。它可以是通过插件,也可以是在同一个function.php文件中,或者使用插件在数据库上创建自定义类型(例如CPT UI)。
我建议你们两个:
projectname_postname
,例如,您将以这样的结尾:stackoverflow_talent
假设您选择第二个,只需以这种方式对该特定帖子类型使用slug重写:
register_post_type( 'myproject_talent',
array(
'labels' => array(
'name' => __( 'Talent' ),
'singular_name' => __( 'talent' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'talent'),
)
);
现在,您的所有帖子都会显示/talent/
路径。
请记住在创建帖子类型后刷新永久链接结构,否则您无法在前端看到它。
希望解决你的问题。
答案 1 :(得分:0)
我有同样的问题,但答案对我不起作用。如果其他人发现此信息,请确保帖子类型名称不超过20个字符。这可能是问题,Wordpress不会在意你知道。