Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress JSON API: Retrieve multiple posts by ids

I am using the WordPress JSON API plugin with my website. https://wordpress.org/plugins/json-api/

I'm attempting to retrieve multiple posts, by their ids through a REST call.

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

According to the plugin documentation, get_posts supports all parameters of the WP_QUERY function, so this should work. However, this call returns

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

  ],
  "query": {
    "ignore_sticky_posts": true,
    "post__in": "7742,20715"
  }
}

Note that the posts aren't returned. However, I have verified these post ids to be valid and correct.

Am I calling the json api incorrectly?

Thank you,

William

like image 478
Billy Ryan Avatar asked Aug 24 '14 22:08

Billy Ryan


1 Answers

you can fetch by IDs by use simple code:

http://demo.wp-api.org/wp-json/wp/v2/posts?include=1,35
like image 64
hs777it Avatar answered Oct 16 '22 15:10

hs777it