[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
Tue Jul 28 19:07:26 UTC 2020
#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: Query | Version: 5.4.1
Severity: critical | Resolution:
Keywords: | Focuses: rest-api
--------------------------+------------------------------
Comment (by emrikol):
IF the patch in reply 2 works for you, I believe you can do it in a
filter, rather than hacking core after every update:
{{{#!php
<?php
add_filter( 'rest_page_query', function( $args, $request ) {
if (
isset( $args['orderby'] ) &&
is_string( $args['orderby'] ) &&
'menu_order' === $args['orderby']
) {
$args['orderby'] = [ 'menu_order' => 'ASC', 'ID' => 'ASC'
];
}
return $args;
}, 10, 2 );
}}}
In my testing when I ran into this issue, I also needed to bump up
`posts_per_page` as well since it was still very low compared to the
number of pages on the site experiencing the issue.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46294#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list