Wordpress创建一个自定义休息服务


Wordpress create a custom rest service

我正在开发一个wordpress插件,我想创建一个带有JSON输出的页面,其中包含一些自定义的数据库查询,我将从javascript中使用这些查询。

什么是最佳实践?

我试着将wp-api与自定义控制器一起使用,但我不需要那个插件。。

也许最好创建一个自定义的.php文件,使用wordpress对象查询带有json输出的数据库?

感谢

我选择创建一个自定义的.php文件,我不知道这是否是更好的选择,但它有效:)

<?php
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] = 'GET') {
    require_once '../../../../wp-blog-header.php';
    require_once '../includes/engine.php';
    $engine = new Engine();
    echo json_encode($engine->Data());
}