是否有方法向已注册的自定义分类法添加参数?我所有的分类法都是用插件构建的,所以如果我能为函数添加一些东西就好了。php,只需将“重写”=>数组(“分层”=>true)添加到这些分类法中。
您应该能够使用register_taxonomy
重新注册要影响的分类法。
http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/taxonomy.php#L305
警告:未测试的代码
(大多数情况下,我只是一时兴起。我对损坏的网站不承担任何责任):
function reregister_taxonomy() {
# the post types that the taxonomy is registered to
$post_types = array(\'post\');
# set this to the taxonomy name
$tax_name = \'TAXONOMY_NAME_TO_CHANGE\';
# load the already created taxonomy as array so we can
# pass it back in as $args to register_taxonomy
$tax = (array)get_taxonomy($tax_name);
if ($tax) {
# adjust the hierarchical necessities
$tax[\'hierarchical\'] = true;
$tax[\'rewrite\'][\'hierarchical\'] = true;
# adjust the hierarchical niceties (these could be ignored)
$tax[\'labels\'][\'parent_item\'] = sprintf(__("Parent %s"),
$tax->labels->singular_name);
$tax[\'labels\'][\'parent_item_colon\'] = sprintf(__("Parent %s:"),
$tax->labels->singular_name);
# cast caps to array as expected by register_taxonomy
$tax[\'capabilities\'] = (array)$tax[\'cap\'];
# cast labels to array
$tax[\'labels\'] = (array)$tax[\'labels\'];
# register the taxonomy with our new settings
register_taxonomy($tax_name, array(\'post\'), $tax);
}
}
# init action with a late priority so other taxonomies are loaded
# alternatively could be done with the `registered_taxonomy` action hook
add_action(\'init\', \'reregister_taxonomy\', 9999);
写了这篇文章之后,我才意识到这个问题已经有一年半的历史了,也许有人会觉得它很有用。