【发布时间】:2019-10-09 09:32:35
【问题描述】:
我正在使用以下代码注册自定义 WordPress 端点:
add_action('rest_api_init', function(){
register_rest_route('custom', array(
'methods' => 'GET',
'callback' => 'return_custom_data',
));
});
function return_custom_data(){
return 'test';
}
但是,这是我向它发送请求时得到的结果:
{'namespace': 'custom', 'routes': {'/custom': {'namespace': 'custom', 'methods': ['GET'], 'endpoints': [{'methods': ['GET'], 'args': {'namespace': {'required': False, 'default': 'custom'}, 'context': {'required': False, 'default': 'view'}}}], '_links': {'self': 'http://localhost/index.php/wp-json/custom'}}}, '_links': {'up': [{'href': 'http://localhost/index.php/wp-json/'}]}}
它确实识别了端点,但是我在回调中指定的数据没有返回。
有什么建议吗?
谢谢!
【问题讨论】:
标签: wordpress wordpress-rest-api