Make WordPress Core

Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#42671 closed enhancement (wontfix)

REST - getting all taxonomy terms with one GET request causes division by zero warning.

Reported by: tmuikku's profile tmuikku Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords:
Focuses: Cc:


Querying taxonomy terms from REST API one can affect the returned items number by using per_page REST argument, like so:

Minimum value for this argument is 1, which is annoying in the taxonomy terms context. One have to use a filter to change per_page minimum value to 0 to be able to get all terms at once.

The per_page argument for taxonomy terms route is set in WP_REST_Terms_Controller parent WP_REST_Controller, see get_collection_params() method.

Here is an filter example to allow per_page value 0:

add_filter( "rest_customtaxonomy_collection_params", 'myplugin_rest_customtaxonomy_collection_params_filter');
function myplugin_rest_customtaxonomy_collection_params_filter($query_params) {
    $query_params['per_page']['minimum'] = 0;
    return $query_params;

Now all terms are returned with GET request:

But now a PHP warning "Division by zero" emerges in

Please, fix the division by zero warning.
Preferably, also set the per_page minimum value to 0 in WP_REST_Terms_Controller::get_collection_params()


Change History (2)

#1 @TimothyBlynJacobs
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version changed from 4.9 to 4.7

Hi @tmuikku,

Apologies for the delay in providing a response.

The REST API does not support unbounded pagination. Instead, it is recommended to query through subsequent pages or increasing the maximum to a value that works for your website.

This was discussed at length during the Gutenberg project. I think this PR is a good jumping off place to read more about the discussion:

#2 @TimothyBlynJacobs
5 years ago

  • Resolution changed from invalid to wontfix
Note: See TracTickets for help on using tickets.