[wp-trac] [WordPress Trac] #46294: wp rest api fails to paginate page requests correctly when ordering on menu_order

WordPress Trac noreply at wordpress.org
Thu Feb 21 06:31:02 UTC 2019


#46294: wp rest api fails to paginate page requests correctly when ordering on
menu_order
--------------------------+------------------------------
 Reporter:  hobzhobz      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by hobzhobz):

 * focuses:  rest-api =>
 * component:  REST API => General


Comment:

 Here is a hack to fix the issue:

 In the file /wp-includes/rest-api/endpoints/class-wp-rest-posts-
 controller.php:290

 around line 290.
 change from:
 {{{#!php
 $posts_query  = new WP_Query();
 $query_result = $posts_query->query( $query_args );
 }}}

 to

 {{{#!php
 $posts_query  = new WP_Query();
 if (isset($query_args['orderby']) && is_string($query_args['orderby']) &&
 $query_args['orderby'] == 'menu_order') {
     $query_args['orderby'] = ['menu_order' => 'ASC', 'ID' => 'ASC'];
 }
 $query_result = $posts_query->query( $query_args );
 }}}

 now the query will be deterministic between pages.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46294#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list