Ticket #17123 (closed defect (bug): fixed)
WP_User_Query ordered by post_count doesn't work if prefix is not wp_
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1.2 |
| Component: | Users | Version: | 3.1 |
| Severity: | major | Keywords: | has-patch |
| Cc: |
Description
If you try this:
$q = WP_User_Query( array( 'orderby' => 'post_count' ) );
it won't work if your table prefix is different than 'wp_', because it's hard coded in wp-includes/user.php line 441 :
$this->query_from .= " LEFT OUTER JOIN (
SELECT post_author, COUNT(*) as post_count
FROM wp_posts
$where
GROUP BY post_author
) p ON ({$wpdb->users}.ID = p.post_author)
";
it should be replaced by:
$this->query_from .= " LEFT OUTER JOIN (
SELECT post_author, COUNT(*) as post_count
FROM $wpdb->posts
$where
GROUP BY post_author
) p ON ({$wpdb->users}.ID = p.post_author)
";
Attachments
Change History
- Keywords needs-testing added
Great catch! I added a patch file so others can test it out on their local installations without having to hunt and change the code.
- Keywords needs-testing removed
Thanks for the report and the patch.
- Status changed from new to closed
- Resolution set to fixed
Note: See
TracTickets for help on using
tickets.


introduced in [15491]