WP REST API v2: receiving messages by mail

I am trying to get all messages by ID using the WP REST API. According to the documentation, we can use a filter to use WP Query arguments. Using this with message endpoints returns all messages.

http://demo.wp-api.org/wp-json/wp/v2/posts/?filter[posts__in]=470,469
+4
source share
2 answers

You can get a single record by identifier, for example

http://demo.wp-api.org/wp-json/wp/v2/posts/?filter[p]=470

But according to support, it will not work for multiple messages.

https://github.com/WP-API/WP-API/issues/1368

So you can start the loop and get one after the other.

But for several you need to put a function

add_filter('rest_query_vars', 'custom_rest_query_vars');
function custom_rest_query_vars($query_vars) {
  $query_vars = array_merge( $query_vars,    array('post','post__in','type','id') );
  return $query_vars;
}

Then you need to run

+filter[post__in][]=470&filter[post__in][]=469
+1
source

With V2, it works for me, more oil, and then it adds its own code

http://demo.wp-api.org/wp-json/wp/v2/posts?include[]=470&include[]=469
+1

Source: https://habr.com/ru/post/1662105/


All Articles