Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#13048 closed defect (bug) (fixed)

WP_Query gets the user ID for author archives twice

Reported by: simonwheatley Owned by: ryan
Priority: normal Milestone: 3.0
Component: Query Version:
Severity: minor Keywords: has-patch
Cc: westi

Description (last modified by dd32)

Currently WP_Query->get_posts does this:

			$q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'");
			$q['author'] = get_user_by('slug', $q['author_name']);

Which potentially hits the DB twice for the same info. Looks like an old bit of functionality got left in when the get_user_by call was added. Would be better if it went like this:

			$q['author'] = get_user_by('slug', $q['author_name']);

Attachments (1)

do not get author ID twice.diff (644 bytes) - added by simonwheatley 3 years ago.
A diff to stop WP_Query hitting the DB twice for the author ID on author archives

Download all attachments as: .zip

Change History (6)

A diff to stop WP_Query hitting the DB twice for the author ID on author archives

Ugh. Wrong format for the codeblocks in the description, sorry... see the diff. :/

comment:2   dd323 years ago

  • Description modified (diff)

fixed the code in the desc.

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0
  • Resolution set to fixed
  • Status changed from new to closed

comment:5   dd323 years ago

Thanks scribu

Note: See TracTickets for help on using tickets.