diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php
index 2f3da47..d0aa445 100644
--- a/src/wp-includes/class-wp-term-query.php
+++ b/src/wp-includes/class-wp-term-query.php
@@ -686,60 +686,77 @@ class WP_Term_Query {
 			return $this->terms;
 		}
 
+		/**
+		 * Filters the terms array before the query takes place.
+		 *
+		 * Return a non-null value to bypass WordPress's default terms queries.
+		 *
+		 * @param array|null $terms Return an array of term data to short-circuit WP's query,
+		 *                          or null to allow WP to run its normal queries.
+		 * @param WP_Term_Query   $this  The WP_Term_Query instance, passed by reference.
+		 */
+		$terms = apply_filters_ref_array( 'terms_pre_query', array( null, &$this ) );
+
 		if ( 'count' == $_fields ) {
-			$count = $wpdb->get_var( $this->request );
-			wp_cache_set( $cache_key, $count, 'terms' );
-			return $count;
-		}
+			if( null ===  $terms ) {
+				$count = $wpdb->get_var( $this->request );
+				wp_cache_set( $cache_key, $count, 'terms' );
+				return $count;
+			}
 
-		$terms = $wpdb->get_results( $this->request );
-		if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) {
-			update_term_cache( $terms );
+			return count( $terms );
 		}
 
-		// Prime termmeta cache.
-		if ( $args['update_term_meta_cache'] ) {
-			$term_ids = wp_list_pluck( $terms, 'term_id' );
-			update_termmeta_cache( $term_ids );
-		}
+		if( null ===  $terms ) {
+			$terms = $wpdb->get_results( $this->request );
+			if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) {
+				update_term_cache( $terms );
+			}
 
-		if ( empty( $terms ) ) {
-			wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS );
-			return array();
-		}
+			// Prime termmeta cache.
+			if ( $args['update_term_meta_cache'] ) {
+				$term_ids = wp_list_pluck( $terms, 'term_id' );
+				update_termmeta_cache( $term_ids );
+			}
 
-		if ( $child_of ) {
-			foreach ( $taxonomies as $_tax ) {
-				$children = _get_term_hierarchy( $_tax );
-				if ( ! empty( $children ) ) {
-					$terms = _get_term_children( $child_of, $terms, $_tax );
+			if ( empty( $terms ) ) {
+				wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS );
+				return array();
+			}
+
+			if ( $child_of ) {
+				foreach ( $taxonomies as $_tax ) {
+					$children = _get_term_hierarchy( $_tax );
+					if ( ! empty( $children ) ) {
+						$terms = _get_term_children( $child_of, $terms, $_tax );
+					}
 				}
 			}
-		}
 
-		// Update term counts to include children.
-		if ( $args['pad_counts'] && 'all' == $_fields ) {
-			foreach ( $taxonomies as $_tax ) {
-				_pad_term_counts( $terms, $_tax );
+			// Update term counts to include children.
+			if ( $args['pad_counts'] && 'all' == $_fields ) {
+				foreach ( $taxonomies as $_tax ) {
+					_pad_term_counts( $terms, $_tax );
+				}
 			}
-		}
 
-		// Make sure we show empty categories that have children.
-		if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) {
-			foreach ( $terms as $k => $term ) {
-				if ( ! $term->count ) {
-					$children = get_term_children( $term->term_id, $term->taxonomy );
-					if ( is_array( $children ) ) {
-						foreach ( $children as $child_id ) {
-							$child = get_term( $child_id, $term->taxonomy );
-							if ( $child->count ) {
-								continue 2;
+			// Make sure we show empty categories that have children.
+			if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) {
+				foreach ( $terms as $k => $term ) {
+					if ( ! $term->count ) {
+						$children = get_term_children( $term->term_id, $term->taxonomy );
+						if ( is_array( $children ) ) {
+							foreach ( $children as $child_id ) {
+								$child = get_term( $child_id, $term->taxonomy );
+								if ( $child->count ) {
+									continue 2;
+								}
 							}
 						}
-					}
 
-					// It really is empty.
-					unset( $terms[ $k ] );
+						// It really is empty.
+						unset( $terms[ $k ] );
+					}
 				}
 			}
 		}
