Ticket #17123 (closed defect (bug): fixed)

Opened 11 months ago

Last modified 11 months ago

WP_User_Query ordered by post_count doesn't work if prefix is not wp_

Reported by: ziofix 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

17123.diff Download (469 bytes) - added by ericmann 11 months ago.
Adding change as a patch file

Change History

  • Milestone changed from Awaiting Review to 3.1.2

introduced in [15491]

Adding change as a patch file

  • 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

(In [17634]) Use proper prefix in query. Fixes user queries ordered by post count. Props ziofix, ericmann. fixes #17123 for trunk

(In [17635]) Use proper prefix in query. Fixes user queries ordered by post count. Props ziofix, ericmann. fixes #17123 for 3.1

Note: See TracTickets for help on using tickets.