admin管理员组文章数量:1423156
I would like to add a REST route that would looks like
.../v1/import/?url=XXX
where XXX is an URL.
I had a try with
register_rest_route('.../v1','import/?url=(?:/(?P<url>\w+))?', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'import_url' ),
'args' => array(
'url' => array(
//'validate_callback' => array($this, 'validateImportUrl')
),
),
)
) );
but it does not work:
{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}
Can anyone help ?
Thanks !
I would like to add a REST route that would looks like
.../v1/import/?url=XXX
where XXX is an URL.
I had a try with
register_rest_route('.../v1','import/?url=(?:/(?P<url>\w+))?', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'import_url' ),
'args' => array(
'url' => array(
//'validate_callback' => array($this, 'validateImportUrl')
),
),
)
) );
but it does not work:
{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}
Can anyone help ?
Thanks !
Share Improve this question asked Jun 19, 2019 at 19:23 gordiegordie 4925 silver badges19 bronze badges 1- Query parameters don't belong in the route, they should be added as arguments, which you've already done. – Jacob Peattie Commented Jun 20, 2019 at 1:40
1 Answer
Reset to default -1Regex problem, I found out :)
register_rest_route( '.../v1', 'import(?:/?url=(?P<url>\d+))?', array(
本文标签: how can I add an URL parameter to a rest route using registerrestroute()
版权声明:本文标题:how can I add an URL parameter to a rest route using register_rest_route()? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745387583a2656443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论