Skip to content

Add WP_User_Query support for TiDB (SQL_CALC_FOUND_ROWS / FOUND_ROWS)#133

Open
gabamnml wants to merge 1 commit into
mitchmac:mainfrom
gabamnml:patch-1
Open

Add WP_User_Query support for TiDB (SQL_CALC_FOUND_ROWS / FOUND_ROWS)#133
gabamnml wants to merge 1 commit into
mitchmac:mainfrom
gabamnml:patch-1

Conversation

@gabamnml

@gabamnml gabamnml commented Jun 16, 2026

Copy link
Copy Markdown

Summary

Extends the existing WP_Query workaround to also cover WP_User_Query, which uses the same deprecated MySQL features. Without this, the WordPress admin Users screen shows correct tab counts (e.g. "All (3)") but the table displays "No users found."

Problem

TiDB does not support SQL_CALC_FOUND_ROWS or FOUND_ROWS(). WordPress admin list tables rely on these for paginated queries:

Screen Count (works) List table (broken without fix)
Posts wp_count_posts() WP_Query
Users count_users() WP_User_Query

The plugin already patches WP_Query via found_posts_query, posts_pre_query, and related filters. WP_User_Query was not covered, so posts could display correctly while users could not.

Solution

Mirror the WP_Query approach for WP_User_Query:

  1. users_pre_query — Strip SQL_CALC_FOUND_ROWS from $query->query_fields before the SELECT is built and executed.
  2. found_users_query — Replace SELECT FOUND_ROWS() with a COUNT(*) (or COUNT(DISTINCT wp_users.ID) when DISTINCT is present) using the query's existing query_from and query_where clauses.

Also harden wtc_remove_found_rows_query() to use preg_replace instead of str_replace, so removal works whether SQL_CALC_FOUND_ROWS appears after SELECT or at the start of query_fields.

Changes

  • Register found_users_query and users_pre_query filters in wtc_init().
  • Add wtc_add_found_users_query() for total user count on TiDB.
  • Update wtc_remove_found_rows_query() to reliably remove SQL_CALC_FOUND_ROWS in all positions.

Environment

Reproduced on WordPress 6.9.x with TiDB Cloud (MySQL-compatible protocol). Posts were fixed by activating this plugin; users remained broken until WP_User_Query was patched.

fix to show the users list
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

@gabamnml is attempting to deploy a commit to the Mitch MacKenzie's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify

netlify Bot commented Jun 16, 2026

Copy link
Copy Markdown

👷 Deploy request for serverlesswp pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 06867ef

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.

1 participant