WP Rest API发送总计数(found_posts) WP\\U查询中的属性。在名为X-WP-Total
.
FOR POSTS: 您可以调用REST API的posts端点
http://demo.wp-api.org/wp-json/wp/v2/posts
posts count的值在标头中返回为
X-WP-Total
. 下面是托管演示的响应示例
Access-Control-Allow-Headers:Authorization, Content-Type
Access-Control-Expose-Headers:X-WP-Total, X-WP-TotalPages
Allow:GET
Cache-Control:max-age=300, must-revalidate
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/json; charset=UTF-8
Date:Wed, 28 Dec 2016 12:48:50 GMT
Last-Modified:Wed, 28 Dec 2016 12:48:50 GMT
Link:<https://demo.wp-api.org/wp-json/wp/v2/posts?page=2>; rel="next"
Server:nginx/1.4.6 (Ubuntu)
Transfer-Encoding:chunked
Vary:Cookie
Via:1.1 dfa2cbb51ec90b28f03125592b887c7d.cloudfront.net (CloudFront)
X-Amz-Cf-Id:ri4C3e-AdixwqGv_wYNdGRq9ChsIroy1Waxe2GqkiTqbk4CpiSIQfw==
X-Batcache:MISS
X-Cache:Miss from cloudfront
X-Content-Type-Options:nosniff
X-EC2-Instance-Id:i-198c7e94
X-Powered-By:PHP/7.0.11-1+deb.sury.org~trusty+1
X-Robots-Tag:noindex
X-WP-Total:71
X-WP-TotalPages:8
NOTE:
您还可以限制
posts per page 你的帖子数达到了1,所以你并不是为了得到帖子数而获得所有的wordpress帖子
http://demo.wp-api.org/wp-json/wp/v2/posts?per_page=1
要获取所有类别,只需在以下位置向类别端点发出Get请求:
http://demo.wp-api.org/wp-json/wp/v2/categories
这将返回所有类别,并且可以在
X-WP-Total
标题。