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
This commit is contained in:
Peter Westwood 2011-08-24 10:39:52 +00:00
parent ddfa97ee0a
commit 89a6ae387e
1 changed files with 3 additions and 2 deletions

View File

@ -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);