From ebecb8ffdf0eeddf97c65f964c0caabf18bd9b57 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 22 Mar 2011 20:06:38 +0000 Subject: [PATCH] Return false instead of WP_Error from get_term_by() if the term does not exist. Makes fetching a term by id consistent with slug and name. Props hakre. fixes #16464 #16717 for trunk git-svn-id: http://svn.automattic.com/wordpress/trunk@17526 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 4 ++-- wp-includes/taxonomy.php | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 8725dd81f..95ecb7a64 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2190,7 +2190,7 @@ class WP_Query { if ( !empty( $cat_query ) ) { $cat_query = reset( $cat_query ); $the_cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); - if ( $the_cat && ! is_wp_error( $the_cat ) ) { + if ( $the_cat ) { $this->set( 'cat', $the_cat->term_id ); $this->set( 'category_name', $the_cat->slug ); } @@ -2202,7 +2202,7 @@ class WP_Query { if ( !empty( $tag_query ) ) { $tag_query = reset( $tag_query ); $the_tag = get_term_by( $tag_query['field'], $tag_query['terms'][0], 'post_tag' ); - if ( $the_tag && ! is_wp_error( $the_tag ) ) { + if ( $the_tag ) { $this->set( 'tag_id', $the_tag->term_id ); } unset( $the_tag ); diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 957ce724d..33d4329de 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -889,7 +889,10 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw $value = stripslashes($value); $field = 't.name'; } else { - return get_term( (int) $value, $taxonomy, $output, $filter); + $term = get_term( (int) $value, $taxonomy, $output, $filter); + if ( is_wp_error( $term ) ) + $term = false; + return $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 $field = %s LIMIT 1", $taxonomy, $value) );