Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #12795 - alter orderby for menu_order to ensure unique ordering #23647

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
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 ( 'menu_order' === $query->query['orderby'] ) {
$orderby = "$wpdb->posts.menu_order,$wpdb->posts.post_title,$wpdb->posts.id " . $query->query['order'];
}
}
return $orderby;
}
add_filter( 'posts_orderby', 'gutenberg_posts_orderby', 10, 2 );