register_taxonomy()
是工作的工具。抄本:
此函数用于添加或覆盖分类法。
一种选择是复制register_taxonomy()
$args
并对其进行修改。然而,这意味着未来对原始register_taxonomy()
代码将被覆盖。
因此,至少在这种情况下,最好获取原始参数,修改我想要更改的参数,然后重新注册分类法。此解决方案的灵感来自于本answer to a similar question about custom post types.
使用people
自定义帖子类型和people_category
根据示例中的分类法,可以这样做:
function wpse_modify_taxonomy() {
// get the arguments of the already-registered taxonomy
$people_category_args = get_taxonomy( \'people_category\' ); // returns an object
// make changes to the args
// in this example there are three changes
// again, note that it\'s an object
$people_category_args->show_admin_column = true;
$people_category_args->rewrite[\'slug\'] = \'people\';
$people_category_args->rewrite[\'with_front\'] = false;
// re-register the taxonomy
register_taxonomy( \'people_category\', \'people\', (array) $people_category_args );
}
// hook it up to 11 so that it overrides the original register_taxonomy function
add_action( \'init\', \'wpse_modify_taxonomy\', 11 );
请注意,我在上面键入了第三个
register_taxonomy()
所需数组类型的参数。这不是严格必要的,因为
register_taxonomy()
使用
wp_parse_args()
可以处理
object
或
array
. 也就是说,
register_taxonomy()
\'s
$args
应作为
array
根据法典,我觉得这是对的。