WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13048 closed defect (bug) (fixed)

WP_Query gets the user ID for author archives twice

Reported by: simonwheatley Owned by: 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 4 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)

simonwheatley4 years ago

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

comment:1 simonwheatley4 years ago

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

comment:2 dd324 years ago

  • Description modified (diff)

fixed the code in the desc.

comment:3 scribu4 years ago

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

comment:4 scribu4 years ago

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

comment:5 dd324 years ago

Thanks scribu

Note: See TracTickets for help on using tickets.