7

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

3 Answers 3

12

you can fetch by IDs by use simple code:

http://demo.wp-api.org/wp-json/wp/v2/posts?include=1,35
Sign up to request clarification or add additional context in comments.

1 Comment

Old post, but would be nice if this is the accepted answer.
7

It is possible to fetch only some posts by id by passing include[] with API v2:

http://demo.wp-api.org/wp-json/wp/v2/posts?include[]=496&include[]=503

I've tried it and it works.

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

Comments

0

From a quick look at the source code, it looks like this is not supported:

Line 46 of query.php

$wp_translation = array(
  'json' =>           'json',
  'post_id' =>        'p',
  'post_slug' =>      'name',
  'page_id' =>        'page_id',
  'page_slug' =>      'name',
  'category_id' =>    'cat',
  'category_slug' =>  'category_name',
  'tag_id' =>         'tag_id',
  'tag_slug' =>       'tag',
  'author_id' =>      'author',
  'author_slug' =>    'author_name',
  'search' =>         's',
  'order' =>          'order',
  'order_by' =>       'orderby'
);

I also need this functionality, so when I get a chance I'll write some code for adding this and post it here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.