admin管理员组文章数量:1315089
I am working on a wordpress project that is highly customized. I have custom post type "foo-post" and within there I have a custom field "foo-field" (created by advanced custom fields plugin and is just a simple string).
Now I want to be able to query this "foo-Post" through the REST API. I have managed to include this custom post in API response, but the problem is that I want to filter the output based on "foo-field". Is it possible to create a route that can be called like this:
/wp-json/v2/wp/foo-post?foo-field=something
If so, please help me figure out how to do that.
Thanks in advance
I am working on a wordpress project that is highly customized. I have custom post type "foo-post" and within there I have a custom field "foo-field" (created by advanced custom fields plugin and is just a simple string).
Now I want to be able to query this "foo-Post" through the REST API. I have managed to include this custom post in API response, but the problem is that I want to filter the output based on "foo-field". Is it possible to create a route that can be called like this:
/wp-json/v2/wp/foo-post?foo-field=something
If so, please help me figure out how to do that.
Thanks in advance
Share Improve this question asked Feb 22, 2017 at 7:35 Reza GhochkhaniReza Ghochkhani 112 bronze badges1 Answer
Reset to default 0Actually I found my answer after diving into the WordPress's core code. Yes, it is possible to do such a thing, all you need is to use the following function: register_rest_route
There are some tricky parts though. This function uses regular expressions and now I am going to figure out how to use that in this function.
本文标签: Custom REST endpoints for a custom post type with custom fields
版权声明:本文标题:Custom REST endpoints for a custom post type with custom fields 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741972462a2407922.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论