Make WordPress Core

Opened 7 months ago

#42671 new enhancement

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

Reported by: tmuikku Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
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: wp-json/wp/v2/customtaxonomy?per_page={number}

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: wp-json/wp/v2/customtaxonomy?per_page=0

But now a PHP warning "Division by zero" emerges in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php:271

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 (0)

Note: See TracTickets for help on using tickets.