我正在尝试通过调用我的自定义 Wordpress rest api 来获取所有类别

I am trying to get all categories by calling my custom Wordpress rest api

我正在尝试通过在 android 应用程序中调用 Wordpress rest api 来获取所有类别。 http://demo.wp-api.org/wp-json/wp/v2/categories 我可以通过调用上面的 url 来获取所有类别,但是我已经安装了类别图像插件,所以除了默认模式之外,我还需要获取每个类别图像。 所以我必须制作自己的自定义 rest api 端点。 以下是我的代码。

但是 Wordpress 函数 get_categories returns 为空。 任何人让我知道我的代码中的错误点是什么? 为什么我得不到我想得到的? 我尝试在我的自定义端点函数中调用 get_posts 函数,但它也返回了 null。 那么这篇文章的主要目标是为什么不能在我的自定义端点函数中调用 Wordpress 函数 get_categories 和 get_posts?

register_rest_route($this->namespace, '/'.$this->rest_base, array('methods' => 'GET', 'callback' => array($this, 'get_main_categories')));
...
public function get_main_categories($request) {
$data = get_categories();
$data = rest_ensure_response($data);
return $data;
}

好的。 我明白了。 函数 get_categories returns 仅分类列表中有一个帖子。

如果您的类别小于或等于 100,请使用:

http://demo.wp-api.org/wp-json/wp/v2/categories?per_page=100

你能给我插件名称吗(什么是类别图像插件全名或link)?