Skip to content

Fix for MariaDB re Issue #119#147

Closed
alexgw wants to merge 2 commits into
ColorlibHQ:masterfrom
alexgw:master
Closed

Fix for MariaDB re Issue #119#147
alexgw wants to merge 2 commits into
ColorlibHQ:masterfrom
alexgw:master

Conversation

@alexgw
Copy link
Copy Markdown

@alexgw alexgw commented Feb 3, 2025

puikinsh added a commit that referenced this pull request Jun 2, 2026
…dering

- Fix post order being scrambled on MariaDB / MySQL 8 when menu_order is
  re-normalized after gaps appear: refresh() now re-numbers deterministically
  in PHP instead of via a MySQL user-variable (@row_number) ranking whose
  evaluation order is undefined on those databases. Props @alexgw and
  @sebastiencyr (#147, #119).
- Honor `orderby=include` in get_terms() / wp_get_object_terms() instead of
  overriding it with the custom term order; the term filters now receive $args.
  Props @glebkema (#67, #66).
- Apply custom term ordering when any queried taxonomy is sortable (not only the
  first) and keep the caller's orderby as a fallback tiebreaker. Props @goaround
  (#104).

No asset or data-format changes; fully backward compatible with 2.7.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@puikinsh
Copy link
Copy Markdown
Member

puikinsh commented Jun 2, 2026

Thank you @alexgw — and @sebastiencyr for the original analysis on #119! 🙏

You were right: refresh() re-ranked rows using a MySQL user variable (@row_number) inside a derived table, and that evaluation order is undefined on MariaDB / MySQL 8, so menu_order could get scrambled when the sequence was re-normalized after gaps appeared.

This is fixed in 2.7.1 (just released to WordPress.org). Rather than the UNION ALL approach — which would build one SELECT per post and could get very large on big post types — we re-number deterministically in a small PHP loop, which is DB-agnostic and avoids user variables entirely:

$ordered_ids = $wpdb->get_col( $wpdb->prepare(
    "SELECT ID FROM $wpdb->posts
     WHERE post_type = %s AND post_status IN ('publish','pending','draft','private','future')
     ORDER BY menu_order ASC",
    $object
) );
foreach ( $ordered_ids as $position => $id ) {
    $wpdb->update( $wpdb->posts, [ 'menu_order' => $position + 1 ], [ 'ID' => (int) $id ] );
}

You're both credited in the changelog. Closing as resolved in 2.7.1 — thanks again for chasing this down!

@puikinsh puikinsh closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants