最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Increase per_page limit in REST API

programmeradmin0浏览0评论

WP 4.8.2

We need to increase the per_page limit on responses to a REST API request. afaik – the limit is 100

There used to be a way to filter that parameter, but it seems this filter hook is no longer working: rest_post_collection_params

Is there any way to increase that limit without hacking the code?

We understand the repercussions of increasing the limit, but we need to exceed the per_page in a single call for use in code that will not be distributed.

WP 4.8.2

We need to increase the per_page limit on responses to a REST API request. afaik – the limit is 100

There used to be a way to filter that parameter, but it seems this filter hook is no longer working: rest_post_collection_params

Is there any way to increase that limit without hacking the code?

We understand the repercussions of increasing the limit, but we need to exceed the per_page in a single call for use in code that will not be distributed.

Share Improve this question edited May 6, 2019 at 16:11 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Oct 4, 2017 at 15:50 shanebpshanebp 5,0857 gold badges27 silver badges40 bronze badges 2
  • how can I download this postman collection rest_post_collection_params – Inzamam Malik Commented Apr 30, 2020 at 20:40
  • It is part of the rest api in WP - there is no need to download anything – shanebp Commented May 1, 2020 at 0:08
Add a comment  | 

2 Answers 2

Reset to default 8

The collection params accessed via that filter appear to describe the available query params but are not actually used in the query.

I think what you actually want is the rest_{$this->post_type}_query filter which allows you to modify the args before they are passed to WP_Query::query().

Also keep in mind that on the API request the per_page arg might be set, but internally that is translated to posts_per_page for the actual query args.

Edit: I think I misread the original question...

The rest_{$this->post_type}_collection_params does indeed describe the available params.

You should be able to set the per_page max at $params['per_page']['maximum'].

After some testing, it worked with the following:

function maximum_api_filter($query_params) {
    $query_params['per_page']["maximum"]=200;
    return $query_params;
}
add_filter('rest_page_collection_params', 'maximum_api_filter');

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论