Index: src/wp-includes/taxonomy.php
===================================================================
--- src/wp-includes/taxonomy.php	(revision 37571)
+++ src/wp-includes/taxonomy.php	(working copy)
@@ -1885,61 +1885,58 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param int|string $term     The term to check
+ * @param int|string $_term The term to check
  * @param string     $taxonomy The taxonomy name to use
  * @param int        $parent   Optional. ID of parent term under which to confine the exists search.
- * @return mixed Returns null if the term does not exist. Returns the term ID
+ *
+*@return mixed Returns null if the term does not exist. Returns the term ID
  *               if no taxonomy is specified and the term ID exists. Returns
  *               an array of the term ID and the term taxonomy ID the taxonomy
  *               is specified and the pairing exists.
  */
 function term_exists( $term, $taxonomy = '', $parent = null ) {
-	global $wpdb;
 
-	$select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
-	$tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE ";
+	if ( is_int( $term ) ) {
+		if ( 0 == $term ) {
+			return 0;
+		}
+		$_term = get_term( $term, $taxonomy );
+		if ( is_wp_error( $_term ) || is_null( $_term ) ) {
+			$_term = null;
+		}
 
-	if ( is_int($term) ) {
-		if ( 0 == $term )
-			return 0;
-		$where = 't.term_id = %d';
-		if ( !empty($taxonomy) )
-			return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A );
-		else
-			return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) );
+		return $_term->term_id;
 	}
 
 	$term = trim( wp_unslash( $term ) );
 	$slug = sanitize_title( $term );
 
-	$where = 't.slug = %s';
-	$else_where = 't.name = %s';
-	$where_fields = array($slug);
-	$else_where_fields = array($term);
-	$orderby = 'ORDER BY t.term_id ASC';
-	$limit = 'LIMIT 1';
-	if ( !empty($taxonomy) ) {
-		if ( is_numeric( $parent ) ) {
-			$parent = (int) $parent;
-			$where_fields[] = $parent;
-			$else_where_fields[] = $parent;
-			$where .= ' AND tt.parent = %d';
-			$else_where .= ' AND tt.parent = %d';
-		}
+	$defaults = array(
+		'taxonomy'   => $taxonomy,
+		'hide_empty' => false,
+		'number'     => 1,
+		'orderby'    => 'term_id'
+	);
 
-		$where_fields[] = $taxonomy;
-		$else_where_fields[] = $taxonomy;
+	if ( is_numeric( $parent ) ) {
+		$parent             = (int) $parent;
+		$defaults['parent'] = $parent;
+	}
 
-		if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields), ARRAY_A) )
-			return $result;
+	$args = wp_parse_args( array( 'slug' => $slug ), $defaults );
 
-		return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields), ARRAY_A);
+	$terms = get_terms( $args );
+	if ( empty( $terms ) || is_wp_error( $terms ) ) {
+		$args = wp_parse_args( array( 'name' => $term ), $defaults );
+
+		$terms = get_terms( $args );
+		if ( empty( $terms ) || is_wp_error( $terms ) ) {
+			return null;
+		}
 	}
+	$_term = array_shift( $terms );
 
-	if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields) ) )
-		return $result;
-
-	return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields) );
+	return $_term->term_id;
 }
 
 /**
