From 89a6ae387ef254cadf0d1cfd900f4214b5362dd7 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Wed, 24 Aug 2011 10:39:52 +0000 Subject: [PATCH] Optimise get_term to not query for term_id = 0. Also improve the prepared query to use %d for the term_id. Fixes #18076 props mdawaffe. git-svn-id: https://develop.svn.wordpress.org/trunk@18591 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/taxonomy.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index dee7af8b64..e1a4c353df 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -850,9 +850,10 @@ function &get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { } else { if ( is_object($term) ) $term = $term->term_id; - $term = (int) $term; + if ( !$term = (int) $term ) + return $null; if ( ! $_term = wp_cache_get($term, $taxonomy) ) { - $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %s LIMIT 1", $taxonomy, $term) ); + $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) ); if ( ! $_term ) return $null; wp_cache_add($term, $_term, $taxonomy);