diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
index f1c1bce307..9880368d64 100644
--- src/wp-includes/taxonomy.php
+++ src/wp-includes/taxonomy.php
@@ -1258,52 +1258,68 @@ function update_termmeta_cache( $term_ids ) {
  *               is specified and the pairing exists.
  */
 function term_exists( $term, $taxonomy = '', $parent = null ) {
-	global $wpdb;
+	if ( is_int( $term ) ) {
+		if ( 0 == $term ) {
+			return 0;
+		}
 
-	$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 ";
+		$_term = get_term( $term, $taxonomy );
+		if ( is_wp_error( $_term ) || is_null( $_term ) ) {
+			return null;
+		}
+		if ( ! empty( $taxonomy ) ) {
+			return array(
+				'term_id' => (string) $_term->term_id,
+				'term_taxonomy_id' => (string) $_term->term_taxonomy_id,
+			);
+		}
 
-	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 (string) $_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';
-		}
+	if ( empty( $term ) ) {
+		return null;
+	}
 
-		$where_fields[] = $taxonomy;
-		$else_where_fields[] = $taxonomy;
+	$slug = sanitize_title( $term );
 
-		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;
+	$defaults = array(
+		'get'                    => 'all',
+		'hide_empty'			 => false,
+		'number'                 => 1,
+		'update_term_meta_cache' => false,
+		'orderby'                => 'term_id',
+		'suppress_filter'        => true,
+	);
+
+	if ( is_numeric( $parent ) ) {
+		$defaults['parent'] = (int) $parent;
+	}
+	if ( ! empty( $taxonomy ) ) {
+		$defaults['taxonomy'] = $taxonomy;
+	}
+	$args  = wp_parse_args( array( 'slug' => $term ), $defaults );
+	$terms = get_terms( $args );
+	if ( empty( $terms ) || is_wp_error( $terms ) ) {
+		$args = wp_parse_args( array( 'name' => $term ), $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 ) ) {
+			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;
+	if ( ! empty( $taxonomy ) ) {
+		return array(
+			'term_id' => (string) $_term->term_id,
+			'term_taxonomy_id' => (string) $_term->term_taxonomy_id,
+		);
+	}
 
-	return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields) );
+	return (string) $_term->term_id;
 }
 
 /**
@@ -2227,8 +2243,8 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
 	foreach ( (array) $terms as $term) {
 		if ( !strlen(trim($term)) )
 			continue;
-
 		if ( !$term_info = term_exists($term, $taxonomy) ) {
+
 			// Skip if a non-existent term ID is passed.
 			if ( is_int($term) )
 				continue;
diff --git tests/phpunit/tests/term/getTerm.php tests/phpunit/tests/term/getTerm.php
index 7aeb3f3a5b..62931616f9 100644
--- tests/phpunit/tests/term/getTerm.php
+++ tests/phpunit/tests/term/getTerm.php
@@ -30,6 +30,8 @@ class Tests_Term_GetTerm extends WP_UnitTestCase {
 			array( '%d' )
 		);
 
+		clean_term_cache( $t1['term_id'], 'wptests_tax' );
+
 		return array(
 			array(
 				'term_id' => $t1['term_id'],
diff --git tests/phpunit/tests/term/wpGetObjectTerms.php tests/phpunit/tests/term/wpGetObjectTerms.php
index f68e4f674d..03d3daec2d 100644
--- tests/phpunit/tests/term/wpGetObjectTerms.php
+++ tests/phpunit/tests/term/wpGetObjectTerms.php
@@ -338,6 +338,8 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
 		$wpdb->update( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => 100006 ), array( 'term_taxonomy_id' => $term_2->term_taxonomy_id ) );
 		$wpdb->update( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => 100005 ), array( 'term_taxonomy_id' => $term_3->term_taxonomy_id ) );
 
+		clean_term_cache( array( $term_1->term_id, $term_2->term_id, $term_3->term_id ), $this->taxonomy );
+
 		$set = wp_set_object_terms( $p, array( $t1, $t2, $t3 ), $this->taxonomy );
 
 		$found = wp_get_object_terms( $p, $this->taxonomy, array(
