WordPress使用get_categories_taxonomy过滤器从类别中排除术语

时间:2020-07-15 09:47:44

标签: wordpress

从wordpress文档中,过滤器get_categories_taxonomy($ taxonomy,$ args)允许过滤类别,我的目标是全局过滤所有get_categories()。

这是我尝试做的事情:

<?php 
    class initSite {
         public function __construct(){
            add_filter('get_categories_taxonomy', array($this, 'my_categories_filter'),10,2);
         }
         public function my_categories_filter($taxonomy, $args) {
            $args['exclude'] = array(4);
         }
         ....
    }

现在显示类别:

$categories = get_caregories(array('hide_empty' => false, 'parent' => 0));

当我打印$ categories时,没有任何内容被过滤,并且只是不起作用,您有任何想法吗?

谢谢。

0 个答案:

没有答案
相关问题