[wp-trac] [WordPress Trac] #42671: REST - getting all taxonomy terms with one GET request causes division by zero warning.

WordPress Trac noreply at wordpress.org
Thu Nov 23 12:18:32 UTC 2017


#42671: REST - getting all taxonomy terms with one GET request causes division by
zero warning.
-------------------------+-----------------------------
 Reporter:  tmuikku      |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  REST API     |    Version:  4.9
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 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:

 {{{#!php
 <?php
 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()

 Thanks!

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42671>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list