Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#17123 closed defect (bug) (fixed)

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

Reported by: ziofix's profile ziofix Owned by:
Milestone: 3.1.2 Priority: normal
Severity: major Version: 3.1
Component: Users Keywords: has-patch
Focuses: 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 (1)

17123.diff (469 bytes) - added by ericmann 14 years ago.
Adding change as a patch file

Download all attachments as: .zip

Change History (6)

#1 @dd32
14 years ago

  • Milestone changed from Awaiting Review to 3.1.2

introduced in [15491]

@ericmann
14 years ago

Adding change as a patch file

#2 @ericmann
14 years ago

  • 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.

#3 @ocean90
14 years ago

  • Keywords needs-testing removed

Thanks for the report and the patch.

#4 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

#5 @ryan
14 years ago

(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.