Skip to content

Support has_published_posts arg in WP_User_Query - #146

Merged
roborourke merged 12 commits into
developfrom
support-has-published-posts
Oct 23, 2026
Merged

roborourke merged 12 commits into
developfrom
support-has-published-posts

Conversation

@roborourke

@roborourke roborourke commented May 27, 2024 •

Copy link
Copy Markdown
Contributor

Fixes #145

Maybe not ideal, but similar to the mechanism for finding distinct post_author values in core. Results should be cached I believe.

@roborourke
roborourke requested a review from johnbillion May 27, 2024 14:36
@roborourke roborourke changed the title Support has_published_posts Support has_published_posts arg in WP_User_Query May 28, 2024
@roborourke
roborourke requested a review from mattheu May 30, 2024 16:22
@roborourke

Copy link
Copy Markdown
Contributor Author

@johnbillion or @mattheu, can I chase this one up? Impacting SEO and likely compatilbiity with other code for users

roborourke and others added 4 commits July 29, 2024 15:46
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>
@roborourke

Copy link
Copy Markdown
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 mattheu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix I think to match core behaviour.

@roborourke
roborourke merged commit 355213b into develop Oct 23, 2026
10 checks passed
@roborourke
roborourke deleted the support-has-published-posts branch October 23, 2026 15:27
@roborourke roborourke mentioned this pull request Oct 23, 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.

Guest authors will never appear when has_published_posts user query var is used

2 participants