是否有任何选项可以为WordPress单个帖子和帖子列表获得不同的类型响应? 我的帖子目标列表响应为
[
{"id":1,
"date":"2017-08-20T07:26:55",
"link":"http://localhost/wordpress/2017/08/20/test-post",
"title":{"rendered":"Test post"}
},
{"id":2,
"date":"2017-08-20T07:26:55",
"link":"http://localhost/wordpress/2017/08/20/test-post",
"title":{"rendered":"Test post"}
},
{"id":3,
"date":"2017-08-20T07:26:55",
"link":"http://localhost/wordpress/2017/08/20/test-post",
"title":{"rendered":"Test post"}
},
{"id":4,
"date":"2017-08-20T07:26:55",
"link":"http://localhost/wordpress/2017/08/20/test-post",
"title":{"rendered":"Test post"}
}
]
单个帖子回复
{
"id": 92,
"date": "2017-08-20T07:13:42",
"date_gmt": "2017-08-20T07:13:42",
"guid": {
"rendered": "http://devel8/wp-news/?p=1"
},
"modified": "2017-08-20T07:13:42",
"modified_gmt": "2017-08-20T07:13:42",
"slug": "hello-world-2",
"status": "publish",
"type": "post",
"link": "http://localhost/wordpress/2017/08/20/hello-world-2/",
"title": {
"rendered": "Hello world!"
},
"content": {
"rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
"protected": false
},
"excerpt": {
"rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
"protected": false
},
"author": 1,
"featured_media": 0,
"comment_status": "open",
"ping_status": "open",
"sticky": false,
"template": "",
"format": "standard",
"meta": [],
"categories": [
1
],
"tags": [],
.....
.....
}
}
注意:使用 register_rest_field()和 rest_prepare_post 过滤器,我们可以修改两个(单个帖子和多个帖子)的响应但我们需要单独使用响应。
或
有任何选项可以知道 register_rest_field()的 get_callback 函数中的多个帖子或单个帖子的请求。
提前致谢。
答案 0 :(得分:0)
由于我没有从任何一个得到任何响应和解决方案,所以我决定开发一个WordPress插件,它将满足我的要求,处理单个帖子和帖子列表或多个帖子或循环的WP REST API请求响应帖子或帖子组不同,管理员可以从后端控制。
经过长时间的努力,我开发了名为
的插件One Call – WP REST API Extension
插件的核心功能
希望这个插件可以帮助像我这样的人,他们计划使用Ionic,Phonegap,React Native,Framework&amp; amp;计划为WordPress网站开发移动应用程序。和NativeScript等。