Repository navigation
Support has_published_posts arg in WP_User_Query - #146
Merged
Merged
Conversation
has_published_posts arg in WP_User_Query
Contributor
Author
|
@johnbillion or @mattheu, can I chase this one up? Impacting SEO and likely compatilbiity with other code for users |
The attributed author subquery joined every term on a post and cast its slug to a user ID, so a tag or category slug that happened to be numeric could add an unrelated user to the results. It now joins only terms in the authorship taxonomy, with inner joins since the joins are required. has_published_posts => true, which core treats as all public post types, was skipped by the is_array() check, so those queries still only matched post_author. It now resolves the post types the same way core does. The blog_id check also matches core, so the clause is left alone when core doesn't add it. The core clause is still rebuilt and replaced with str_replace(). If core changes that SQL the replacement silently stops matching and the query falls back to post_author, which the tests on each supported WordPress version would catch. Tests are split into one case per query shape, with new cases for true and for a numeric tag slug. Both fail against the previous code. Also fixes the PHPCS errors that were failing CI. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Since author terms are named after the display name, a display name can be a number that matches another user's ID. The query reads the user ID from the term slug, which wp_update_term() keeps when only the name changes, so the renamed author still matches and the other user does not. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@johnbillion it'd be great to land this one finally if you have a moment, it's not too big. I'm aiming to get a 0.4.0 release out. |
mattheu
approved these changes
Oct 23, 2026
mattheu
left a comment
Member
There was a problem hiding this comment.
Good fix I think to match core behaviour.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #145
Maybe not ideal, but similar to the mechanism for finding distinct post_author values in core. Results should be cached I believe.