WordPress JSON API:通过 id 检索多个帖子

Bil*_*yan 4 arrays rest wordpress json

我在我的网站上使用 WordPress JSON API 插件。https://wordpress.org/plugins/json-api/

我正在尝试通过 REST 调用通过其 ID 检索多个帖子。

例如:http : //www.example.org/api/core/get_posts/?posts__in=7742,20715

根据插件文档,get_posts 支持 WP_QUERY 函数的所有参数,所以这应该可以工作。但是,此调用返回

{
  "status": "ok",
  "count": 0,
  "count_total": 0,
  "pages": 0,
  "posts": [

  ],
  "query": {
    "ignore_sticky_posts": true,
    "post__in": "7742,20715"
  }
}
Run Code Online (Sandbox Code Playgroud)

请注意,帖子不会返回。但是,我已验证这些帖子 ID 是有效且正确的。

我是否错误地调用了 json api?

谢谢,

威廉

aal*_*aap 6

include[]通过传递API v2可以仅按 id 获取某些帖子:

http://demo.wp-api.org/wp-json/wp/v2/posts?include[]=496&include[]=503
Run Code Online (Sandbox Code Playgroud)

我已经尝试过并且有效。

来源:https ://github.com/WP-API/WP-API/issues/1368#issuecomment-290136087


hs7*_*7it 5

您可以使用简单的代码按 ID 获取:

http://demo.wp-api.org/wp-json/wp/v2/posts?include=1,35
Run Code Online (Sandbox Code Playgroud)