Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#13048 closed defect (bug) (fixed)

WP_Query gets the user ID for author archives twice

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

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 13 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)

@simonwheatley
13 years ago

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

#1 @simonwheatley
13 years ago

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

#2 @dd32
13 years ago

  • Description modified (diff)

fixed the code in the desc.

#3 @scribu
13 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0

#4 @scribu
13 years ago

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

#5 @dd32
13 years ago

Thanks scribu

Note: See TracTickets for help on using tickets.