简体   繁体   English

修改预先存在的分类

[英]Modifying a pre-existing taxonomy

I have a theme that registers a flat taxonomy of tags and I need to convert it into a hierarchical taxonomy.我有一个注册标签的平面分类法的主题,我需要将其转换为分层分类法。 Is there any way to modify a preexisting taxonomy (without editing my theme's files)?有没有办法修改预先存在的分类法(不编辑我的主题文件)?

There's a hook called register_taxonomy_args that should get you what you want.有一个叫做register_taxonomy_args的钩子应该可以得到你想要的。 The constructor for the WP_Taxonomy object calls the method set_props which calls this hook very early on. WP_Taxonomy object 的构造函数调用set_props方法,该方法很早就调用了这个钩子。 Here's a quick (but untested) example:这是一个快速(但未经测试)的示例:


add_filter(
    'register_taxonomy_args',
    static function (array $args, string $taxonomy, array $object_type) {
        if ('my-taxonomy' === $taxonomy) {
            $args['hierarchical'] = true;
        }
        return $args;
    },
    10,
    3
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM