Get post count in wp rest API v2 and get all categories

The WP Rest API sends the total count(found_posts) property from WP_Query. in a header called X-WP-Total. FOR POSTS: you can make a call to posts endpoint of the REST API http://demo.wp-api.org/wp-json/wp/v2/posts The value for posts count is returned in the header as X-WP-Total. Below is a sample response from the hosted demo Access-Control-Allow-Headers:Authorization, Content-Type Access-Control-Expose-Headers:X-WP-Total, … Read more

How do I access the body of a WP API request in a custom route?

You can use $request->get_json_params() which will return an array of key => values. With these conditions(possibly a few more): The client sending the request has Content-Type: application/json in the header There is a raw body like {“option”:”siteColor”,”value”:”ff0000″}. https://developer.wordpress.org/reference/classes/wp_rest_request/get_json_params/