From 76eb5b81389e8f0ff7ea465249153aa8b982f290 Mon Sep 17 00:00:00 2001 From: westi 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: http://svn.automattic.com/wordpress/trunk@18591 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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 dee7af8b6..e1a4c353d 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);