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

WP_Query row counts can be incorrect if query is filtered (seen in bbPress) #341

rmc47 opened this Issue Mar 29, 2019 · 1 comment


None yet
2 participants
Copy link

rmc47 commented Mar 29, 2019


if( ! empty( $found_rows ) )
performs a COUNT() query to find the number of rows that would be returned if $limits did not apply.

However, if the posts_request filter causes the query to be changed, this row count may be invalid. This is the case in bbPress, where the _bbp_has_replies_where filter alters the WHERE clause to include the original topic as well as its replies in a single query.

Instead, we could perform the row count on the query after any filters have been applied if possible.

Incoming PR to do that, but it's a little scary...


This comment has been minimized.

Copy link

patrickebates commented Apr 5, 2019

FYI, we are reviewing this. I keep thinking there is another case where the COUNT() is executed later in the code, perhaps in WPDB. I believe the preferred situation would be to execute it as close to the submission of the query to the DB as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.