为什么我会得到无效的post类型:
function keyword_pages_init() {
$args = array(
'label' => 'Keywords',
'public' => true,
'show_ui' => true,
'capability_type' => 'page',
'hierarchical' => false,
'rewrite' => array('slug' => 'keyword'),
'query_var' => true,
'menu_icon' => 'dashicons-admin-page',
'supports' => array(
'title',
'editor',
'excerpt',
// 'trackbacks',
//'custom-fields',
//'comments',
'revisions',
'thumbnail',
'author',
'page-attributes',
)
);
register_post_type( 'keyword', $args );
}
add_action( 'init', 'keyword_pages_init' );出什么问题了?
但是,使用带有s的关键字是可以的:
function keyword_pages_init() {
$args = array(
'label' => 'Keywords',
'public' => true,
'show_ui' => true,
'capability_type' => 'page',
'hierarchical' => false,
'rewrite' => array('slug' => 'keywords'),
'query_var' => true,
'menu_icon' => 'dashicons-admin-page',
'supports' => array(
'title',
'editor',
'excerpt',
// 'trackbacks',
//'custom-fields',
//'comments',
'revisions',
'thumbnail',
'author',
'page-attributes',
)
);
register_post_type( 'keywords', $args );
}
add_action( 'init', 'keyword_pages_init' );为什么!??
但是它适用于一个新的函数名!
function keyword2_pages_init() {
$args = array(
'label' => 'Keywordsx',
'public' => true,
'show_ui' => true,
'capability_type' => 'page',
'hierarchical' => false,
'rewrite' => array('slug' => 'keyword'),
'query_var' => true,
'menu_icon' => 'dashicons-admin-page',
'supports' => array(
'title',
'editor',
'excerpt',
// 'trackbacks',
//'custom-fields',
//'comments',
'revisions',
'thumbnail',
'author',
'page-attributes',
)
);
register_post_type( 'keyword', $args );
}
add_action( 'init', 'keyword2_pages_init' );为什么!!?
发布于 2017-04-06 13:09:06
自定义post类型“关键字”很可能已经注册。列出所有具有此功能的挂号邮件类型:
var_dump(get_post_types());
基本上,名称“关键字”将是合法的-从文档:
$post_type (字符串)(必需) Post类型。(最大20个字符,不能包含大写字母或空格)默认值:无
如果您确信slug关键字不用于其他事情,而且错误仍然存在,那么它也可能是WordPress核心中的一个bug。如果你能找到什么报告的话。
特别是在过去的数百个WordPress项目中,我也遇到过一次或者两次这样的问题。
如果post类型已经存在--如何取消注册--可以在这里找到post类型(但是,它可能是由于另一个插件或类似的原因而注册的):https://wordpress.stackexchange.com/questions/3820/deregister-custom-post-types
此外,您应该注意到,add_action也有一个$priority参数。优先权可能很重要。
发布于 2017-04-06 13:02:23
register_post_type(‘关键字’,$args );
我认为关键字已经按主题或保留关键字使用了,您可以使用sum前缀(如pre_keyword )来更改此关键字。
如果不工作,也换鼻涕虫。
这会解决我认为的问题。我没有测试它,因为我超出了在这里测试的范围。
https://stackoverflow.com/questions/43255889
复制相似问题