Skip to content

Commit

Permalink
Issue WordPress#12795 - alter orderby for menu_order to ensure unique…
Browse files Browse the repository at this point in the history
…, reproducable ordering
  • Loading branch information
bobbingwide committed Jul 2, 2020
1 parent 50a4dd3 commit bfcba33
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,24 @@ function gutenberg_render_block_with_assigned_block_context( $pre_render, $parse
* @see WP_Block::render
*/
remove_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' );

/**
* Filters a REST query ordered by menu_order to ensure a repeatable sequence over multiple pages.
*
* This can be removed when WordPress core supports pagination of requests ordering on menu_order.
*
* @see https://core.trac.wordpress.org/ticket/46294
*
* @param string $orderby Current orderby value.
* @param WP_Query $query Query object.
*/
function gutenberg_posts_orderby( $orderby, $query ) {
global $wpdb;
if ( defined('REST_REQUEST') && REST_REQUEST ) {
if ( $query->query['orderby'] === 'menu_order' ) {
$orderby = "$wpdb->posts.menu_order,post_title,id asc";
}
}
return $orderby;
}
add_filter( 'posts_orderby', 'gutenberg_posts_orderby', 10, 2 );

0 comments on commit bfcba33

Please sign in to comment.