如何制作自定义的WordPress REST API并获得阿拉伯语语言参数的帖子结果
我创建API路由搜索 我尝试在阿拉伯语中获取一个参数搜索(两个单词) 但这没用,我几乎尝试了视频,但不起作用 尝试Unicode并编码JSON也
有任何解决方案吗?
我的API路由
add_action('rest_api_init', function() {
register_rest_route( 'wm/v1', '/search/(?p<request>.+)', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'wm_search_post',
) );
enter code here
和端点回调功能
function wm_search_post(WP_REST_Request $request){
$req=JSON_encode($request['request']);
return $req;
// here I try to test the results but get rest_no_route
//404 >>> but it is work if I remove parameter
}}
I create API route for search
I try to get a parameter search in Arabic containing about (two words)
but it didn't work, I try almost of video, and not working
try Unicode and encode JSON also
Does anybody have a solution for it?
my API route
add_action('rest_api_init', function() {
register_rest_route( 'wm/v1', '/search/(?p<request>.+)', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'wm_search_post',
) );
enter code here
and the Endpoint callback function
function wm_search_post(WP_REST_Request $request){
$req=JSON_encode($request['request']);
return $req;
// here I try to test the results but get rest_no_route
//404 >>> but it is work if I remove parameter
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的正则表达式不正确,也缺少一些闭合括号。让我们看看以下代码,它在我的末端工作。
您可以得到响应http:// localhost/elementsKit/wp-json/wm/v1/search/&lt; pass_string_here&gt;
希望那会起作用!
Your regex expression is not correct and also some of your closing braces missing. Let's see the below code, it's working on my end.
You can get a response http://localhost/elementskit/wp-json/wm/v1/search/<pass_string_here>
Hope that will work!