get_categories应该返回一个空数组

1 wordpress wordpress-plugin

我正在编写一个文件管理插件,它使用类别系统来创建一个模拟文件系统层次结构,我遇到了一些代码的问题,这些代码负责递归删除'文件夹'(实际上是类别).它不是返回要删除的类别的所有子类别的代码,而是返回一个空数组.有什么想法吗?

    //get all child categories
    $wk_child_categories = get_categories(array('child_of' => $_POST['wk_ID'], 'orderby' => 'term_group'));
    echo " Got the child categories. They are:";
   print_r($wk_child_categories);
Run Code Online (Sandbox Code Playgroud)

Mat*_* R. 6

我可以看到可能导致问题的一件事是缺少post参数.默认情况下,如果您没有post参数,它将回退到标准的Wordpress"post"类型.如果您使用自定义帖子类型,它将返回一个空数组,因为查询正在查找错误的位置.

类别也可能是空的.在参数中,get_categories()有一个hide_empty参数默认不返回空类别,请尝试将其设置为0