wp/wp-includes/class-wp-term-query.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    27 
    27 
    28 	/**
    28 	/**
    29 	 * Metadata query container.
    29 	 * Metadata query container.
    30 	 *
    30 	 *
    31 	 * @since 4.6.0
    31 	 * @since 4.6.0
    32 	 * @var object WP_Meta_Query
    32 	 * @var WP_Meta_Query A meta query instance.
    33 	 */
    33 	 */
    34 	public $meta_query = false;
    34 	public $meta_query = false;
    35 
    35 
    36 	/**
    36 	/**
    37 	 * Metadata query clauses.
    37 	 * Metadata query clauses.
    94 	 *
    94 	 *
    95 	 *     @type string|array $taxonomy               Taxonomy name, or array of taxonomies, to which results should
    95 	 *     @type string|array $taxonomy               Taxonomy name, or array of taxonomies, to which results should
    96 	 *                                                be limited.
    96 	 *                                                be limited.
    97 	 *     @type int|array    $object_ids             Optional. Object ID, or array of object IDs. Results will be
    97 	 *     @type int|array    $object_ids             Optional. Object ID, or array of object IDs. Results will be
    98 	 *                                                limited to terms associated with these objects.
    98 	 *                                                limited to terms associated with these objects.
    99 	 *     @type string       $orderby                Field(s) to order terms by. Accepts term fields ('name',
    99 	 *     @type string       $orderby                Field(s) to order terms by. Accepts:
   100 	 *                                                'slug', 'term_group', 'term_id', 'id', 'description', 'parent'),
   100 	 *                                                - term fields ('name', 'slug', 'term_group', 'term_id', 'id',
   101 	 *                                                'count' for term taxonomy count, 'include' to match the
   101 	 *                                                  'description', 'parent', 'term_order'). Unless `$object_ids`
   102 	 *                                                'order' of the $include param, 'slug__in' to match the
   102 	 *                                                  is not empty, 'term_order' is treated the same as 'term_id'.
   103 	 *                                                'order' of the $slug param, 'meta_value', 'meta_value_num',
   103 	 *                                                - 'count' for term taxonomy count.
   104 	 *                                                the value of `$meta_key`, the array keys of `$meta_query`, or
   104 	 *                                                - 'include' to match the 'order' of the $include param.
   105 	 *                                                'none' to omit the ORDER BY clause. Defaults to 'name'.
   105 	 *                                                - 'slug__in' to match the 'order' of the $slug param.
       
   106 	 *                                                - 'meta_value', 'meta_value_num'.
       
   107 	 *                                                - the value of `$meta_key`.
       
   108 	 *                                                - the array keys of `$meta_query`.
       
   109 	 *                                                - 'none' to omit the ORDER BY clause.
       
   110 	 *                                                Defaults to 'name'.
   106 	 *     @type string       $order                  Whether to order terms in ascending or descending order.
   111 	 *     @type string       $order                  Whether to order terms in ascending or descending order.
   107 	 *                                                Accepts 'ASC' (ascending) or 'DESC' (descending).
   112 	 *                                                Accepts 'ASC' (ascending) or 'DESC' (descending).
   108 	 *                                                Default 'ASC'.
   113 	 *                                                Default 'ASC'.
   109 	 *     @type bool|int     $hide_empty             Whether to hide terms not assigned to any posts. Accepts
   114 	 *     @type bool|int     $hide_empty             Whether to hide terms not assigned to any posts. Accepts
   110 	 *                                                1|true or 0|false. Default 1|true.
   115 	 *                                                1|true or 0|false. Default 1|true.
   111 	 *     @type array|string $include                Array or comma/space-separated string of term ids to include.
   116 	 *     @type array|string $include                Array or comma/space-separated string of term IDs to include.
   112 	 *                                                Default empty array.
   117 	 *                                                Default empty array.
   113 	 *     @type array|string $exclude                Array or comma/space-separated string of term ids to exclude.
   118 	 *     @type array|string $exclude                Array or comma/space-separated string of term IDs to exclude.
   114 	 *                                                If $include is non-empty, $exclude is ignored.
   119 	 *                                                If $include is non-empty, $exclude is ignored.
   115 	 *                                                Default empty array.
   120 	 *                                                Default empty array.
   116 	 *     @type array|string $exclude_tree           Array or comma/space-separated string of term ids to exclude
   121 	 *     @type array|string $exclude_tree           Array or comma/space-separated string of term IDs to exclude
   117 	 *                                                along with all of their descendant terms. If $include is
   122 	 *                                                along with all of their descendant terms. If $include is
   118 	 *                                                non-empty, $exclude_tree is ignored. Default empty array.
   123 	 *                                                non-empty, $exclude_tree is ignored. Default empty array.
   119 	 *     @type int|string   $number                 Maximum number of terms to return. Accepts ''|0 (all) or any
   124 	 *     @type int|string   $number                 Maximum number of terms to return. Accepts ''|0 (all) or any
   120 	 *                                                positive number. Default ''|0 (all). Note that $number may
   125 	 *                                                positive number. Default ''|0 (all). Note that $number may
   121 	 *                                                not return accurate results when coupled with $object_ids.
   126 	 *                                                not return accurate results when coupled with $object_ids.
   122 	 *                                                See #41796 for details.
   127 	 *                                                See #41796 for details.
   123 	 *     @type int          $offset                 The number by which to offset the terms query. Default empty.
   128 	 *     @type int          $offset                 The number by which to offset the terms query. Default empty.
   124 	 *     @type string       $fields                 Term fields to query for. Accepts 'all' (returns an array of
   129 	 *     @type string       $fields                 Term fields to query for. Accepts:
   125 	 *                                                complete term objects), 'all_with_object_id' (returns an
   130 	 *                                                - 'all' Returns an array of complete term objects (`WP_Term[]`).
   126 	 *                                                array of term objects with the 'object_id' param; works only
   131 	 *                                                - 'all_with_object_id' Returns an array of term objects
   127 	 *                                                when the `$object_ids` parameter is populated), 'ids'
   132 	 *                                                  with the 'object_id' param (`WP_Term[]`). Works only
   128 	 *                                                (returns an array of ids), 'tt_ids' (returns an array of
   133 	 *                                                  when the `$object_ids` parameter is populated.
   129 	 *                                                term taxonomy ids), 'id=>parent' (returns an associative
   134 	 *                                                - 'ids' Returns an array of term IDs (`int[]`).
   130 	 *                                                array with ids as keys, parent term IDs as values), 'names'
   135 	 *                                                - 'tt_ids' Returns an array of term taxonomy IDs (`int[]`).
   131 	 *                                                (returns an array of term names), 'count' (returns the number
   136 	 *                                                - 'names' Returns an array of term names (`string[]`).
   132 	 *                                                of matching terms), 'id=>name' (returns an associative array
   137 	 *                                                - 'slugs' Returns an array of term slugs (`string[]`).
   133 	 *                                                with ids as keys, term names as values), or 'id=>slug'
   138 	 *                                                - 'count' Returns the number of matching terms (`int`).
   134 	 *                                                (returns an associative array with ids as keys, term slugs
   139 	 *                                                - 'id=>parent' Returns an associative array of parent term IDs,
   135 	 *                                                as values). Default 'all'.
   140 	 *                                                   keyed by term ID (`int[]`).
   136 	 *     @type bool         $count                  Whether to return a term count (true) or array of term objects
   141 	 *                                                - 'id=>name' Returns an associative array of term names,
   137 	 *                                                (false). Will take precedence over `$fields` if true.
   142 	 *                                                   keyed by term ID (`string[]`).
   138 	 *                                                Default false.
   143 	 *                                                - 'id=>slug' Returns an associative array of term slugs,
       
   144 	 *                                                   keyed by term ID (`string[]`).
       
   145 	 *                                                Default 'all'.
       
   146 	 *     @type bool         $count                  Whether to return a term count. If true, will take precedence
       
   147 	 *                                                over `$fields`. Default false.
   139 	 *     @type string|array $name                   Optional. Name or array of names to return term(s) for.
   148 	 *     @type string|array $name                   Optional. Name or array of names to return term(s) for.
   140 	 *                                                Default empty.
   149 	 *                                                Default empty.
   141 	 *     @type string|array $slug                   Optional. Slug or array of slugs to return term(s) for.
   150 	 *     @type string|array $slug                   Optional. Slug or array of slugs to return term(s) for.
   142 	 *                                                Default empty.
   151 	 *                                                Default empty.
   143 	 *     @type int|array    $term_taxonomy_id       Optional. Term taxonomy ID, or array of term taxonomy IDs,
   152 	 *     @type int|array    $term_taxonomy_id       Optional. Term taxonomy ID, or array of term taxonomy IDs,
   144 	 *                                                to match when querying terms.
   153 	 *                                                to match when querying terms.
   145 	 *     @type bool         $hierarchical           Whether to include terms that have non-empty descendants (even
   154 	 *     @type bool         $hierarchical           Whether to include terms that have non-empty descendants
   146 	 *                                                if $hide_empty is set to true). Default true.
   155 	 *                                                (even if $hide_empty is set to true). Default true.
   147 	 *     @type string       $search                 Search criteria to match terms. Will be SQL-formatted with
   156 	 *     @type string       $search                 Search criteria to match terms. Will be SQL-formatted with
   148 	 *                                                wildcards before and after. Default empty.
   157 	 *                                                wildcards before and after. Default empty.
   149 	 *     @type string       $name__like             Retrieve terms with criteria by which a term is LIKE
   158 	 *     @type string       $name__like             Retrieve terms with criteria by which a term is LIKE
   150 	 *                                                `$name__like`. Default empty.
   159 	 *                                                `$name__like`. Default empty.
   151 	 *     @type string       $description__like      Retrieve terms where the description is LIKE
   160 	 *     @type string       $description__like      Retrieve terms where the description is LIKE
   251 		// 'parent' overrides 'child_of'.
   260 		// 'parent' overrides 'child_of'.
   252 		if ( 0 < intval( $query['parent'] ) ) {
   261 		if ( 0 < intval( $query['parent'] ) ) {
   253 			$query['child_of'] = false;
   262 			$query['child_of'] = false;
   254 		}
   263 		}
   255 
   264 
   256 		if ( 'all' == $query['get'] ) {
   265 		if ( 'all' === $query['get'] ) {
   257 			$query['childless']    = false;
   266 			$query['childless']    = false;
   258 			$query['child_of']     = 0;
   267 			$query['child_of']     = 0;
   259 			$query['hide_empty']   = 0;
   268 			$query['hide_empty']   = 0;
   260 			$query['hierarchical'] = false;
   269 			$query['hierarchical'] = false;
   261 			$query['pad_counts']   = false;
   270 			$query['pad_counts']   = false;
   324 			foreach ( $taxonomies as $_tax ) {
   333 			foreach ( $taxonomies as $_tax ) {
   325 				if ( is_taxonomy_hierarchical( $_tax ) ) {
   334 				if ( is_taxonomy_hierarchical( $_tax ) ) {
   326 					$has_hierarchical_tax = true;
   335 					$has_hierarchical_tax = true;
   327 				}
   336 				}
   328 			}
   337 			}
       
   338 		} else {
       
   339 			// When no taxonomies are provided, assume we have to descend the tree.
       
   340 			$has_hierarchical_tax = true;
   329 		}
   341 		}
   330 
   342 
   331 		if ( ! $has_hierarchical_tax ) {
   343 		if ( ! $has_hierarchical_tax ) {
   332 			$args['hierarchical'] = false;
   344 			$args['hierarchical'] = false;
   333 			$args['pad_counts']   = false;
   345 			$args['pad_counts']   = false;
   336 		// 'parent' overrides 'child_of'.
   348 		// 'parent' overrides 'child_of'.
   337 		if ( 0 < intval( $args['parent'] ) ) {
   349 		if ( 0 < intval( $args['parent'] ) ) {
   338 			$args['child_of'] = false;
   350 			$args['child_of'] = false;
   339 		}
   351 		}
   340 
   352 
   341 		if ( 'all' == $args['get'] ) {
   353 		if ( 'all' === $args['get'] ) {
   342 			$args['childless']    = false;
   354 			$args['childless']    = false;
   343 			$args['child_of']     = 0;
   355 			$args['child_of']     = 0;
   344 			$args['hide_empty']   = 0;
   356 			$args['hide_empty']   = 0;
   345 			$args['hierarchical'] = false;
   357 			$args['hierarchical'] = false;
   346 			$args['pad_counts']   = false;
   358 			$args['pad_counts']   = false;
   377 					$in_hierarchy = true;
   389 					$in_hierarchy = true;
   378 				}
   390 				}
   379 			}
   391 			}
   380 
   392 
   381 			if ( ! $in_hierarchy ) {
   393 			if ( ! $in_hierarchy ) {
   382 				if ( 'count' == $args['fields'] ) {
   394 				if ( 'count' === $args['fields'] ) {
   383 					return 0;
   395 					return 0;
   384 				} else {
   396 				} else {
   385 					$this->terms = array();
   397 					$this->terms = array();
   386 					return $this->terms;
   398 					return $this->terms;
   387 				}
   399 				}
   391 		// 'term_order' is a legal sort order only when joining the relationship table.
   403 		// 'term_order' is a legal sort order only when joining the relationship table.
   392 		$_orderby = $this->query_vars['orderby'];
   404 		$_orderby = $this->query_vars['orderby'];
   393 		if ( 'term_order' === $_orderby && empty( $this->query_vars['object_ids'] ) ) {
   405 		if ( 'term_order' === $_orderby && empty( $this->query_vars['object_ids'] ) ) {
   394 			$_orderby = 'term_id';
   406 			$_orderby = 'term_id';
   395 		}
   407 		}
       
   408 
   396 		$orderby = $this->parse_orderby( $_orderby );
   409 		$orderby = $this->parse_orderby( $_orderby );
   397 
   410 
   398 		if ( $orderby ) {
   411 		if ( $orderby ) {
   399 			$orderby = "ORDER BY $orderby";
   412 			$orderby = "ORDER BY $orderby";
   400 		}
   413 		}
   426 			$excluded_children = $exclude_tree;
   439 			$excluded_children = $exclude_tree;
   427 			foreach ( $exclude_tree as $extrunk ) {
   440 			foreach ( $exclude_tree as $extrunk ) {
   428 				$excluded_children = array_merge(
   441 				$excluded_children = array_merge(
   429 					$excluded_children,
   442 					$excluded_children,
   430 					(array) get_terms(
   443 					(array) get_terms(
   431 						reset( $taxonomies ),
       
   432 						array(
   444 						array(
       
   445 							'taxonomy'   => reset( $taxonomies ),
   433 							'child_of'   => intval( $extrunk ),
   446 							'child_of'   => intval( $extrunk ),
   434 							'fields'     => 'ids',
   447 							'fields'     => 'ids',
   435 							'hide_empty' => 0,
   448 							'hide_empty' => 0,
   436 						)
   449 						)
   437 					)
   450 					)
   540 			$parent                               = (int) $parent;
   553 			$parent                               = (int) $parent;
   541 			$this->sql_clauses['where']['parent'] = "tt.parent = '$parent'";
   554 			$this->sql_clauses['where']['parent'] = "tt.parent = '$parent'";
   542 		}
   555 		}
   543 
   556 
   544 		$hierarchical = $args['hierarchical'];
   557 		$hierarchical = $args['hierarchical'];
   545 		if ( 'count' == $args['fields'] ) {
   558 		if ( 'count' === $args['fields'] ) {
   546 			$hierarchical = false;
   559 			$hierarchical = false;
   547 		}
   560 		}
   548 		if ( $args['hide_empty'] && ! $hierarchical ) {
   561 		if ( $args['hide_empty'] && ! $hierarchical ) {
   549 			$this->sql_clauses['where']['count'] = 'tt.count > 0';
   562 			$this->sql_clauses['where']['count'] = 'tt.count > 0';
   550 		}
   563 		}
   605 				$orderby = '';
   618 				$orderby = '';
   606 				$order   = '';
   619 				$order   = '';
   607 				$selects = array( 'COUNT(*)' );
   620 				$selects = array( 'COUNT(*)' );
   608 				break;
   621 				break;
   609 			case 'id=>name':
   622 			case 'id=>name':
   610 				$selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' );
   623 				$selects = array( 't.term_id', 't.name', 'tt.parent', 'tt.count', 'tt.taxonomy' );
   611 				break;
   624 				break;
   612 			case 'id=>slug':
   625 			case 'id=>slug':
   613 				$selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' );
   626 				$selects = array( 't.term_id', 't.slug', 'tt.parent', 'tt.count', 'tt.taxonomy' );
   614 				break;
   627 				break;
   615 		}
   628 		}
   616 
   629 
   617 		$_fields = $args['fields'];
   630 		$_fields = $args['fields'];
   618 
   631 
   669 		$this->sql_clauses['from']    = "FROM $wpdb->terms AS t $join";
   682 		$this->sql_clauses['from']    = "FROM $wpdb->terms AS t $join";
   670 		$this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : '';
   683 		$this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : '';
   671 		$this->sql_clauses['limits']  = $limits;
   684 		$this->sql_clauses['limits']  = $limits;
   672 
   685 
   673 		$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
   686 		$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
       
   687 
       
   688 		$this->terms = null;
       
   689 
       
   690 		/**
       
   691 		 * Filter the terms array before the query takes place.
       
   692 		 *
       
   693 		 * Return a non-null value to bypass WordPress's default term queries.
       
   694 		 *
       
   695 		 * @since 5.3.0
       
   696 		 *
       
   697 		 * @param array|null    $terms Return an array of term data to short-circuit WP's term query,
       
   698 		 *                             or null to allow WP queries to run normally.
       
   699 		 * @param WP_Term_Query $this  The WP_Term_Query instance, passed by reference.
       
   700 		 */
       
   701 		$this->terms = apply_filters_ref_array( 'terms_pre_query', array( $this->terms, &$this ) );
       
   702 
       
   703 		if ( null !== $this->terms ) {
       
   704 			return $this->terms;
       
   705 		}
   674 
   706 
   675 		// $args can be anything. Only use the args defined in defaults to compute the key.
   707 		// $args can be anything. Only use the args defined in defaults to compute the key.
   676 		$key          = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
   708 		$key          = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
   677 		$last_changed = wp_cache_get_last_changed( 'terms' );
   709 		$last_changed = wp_cache_get_last_changed( 'terms' );
   678 		$cache_key    = "get_terms:$key:$last_changed";
   710 		$cache_key    = "get_terms:$key:$last_changed";
   684 
   716 
   685 			$this->terms = $cache;
   717 			$this->terms = $cache;
   686 			return $this->terms;
   718 			return $this->terms;
   687 		}
   719 		}
   688 
   720 
   689 		if ( 'count' == $_fields ) {
   721 		if ( 'count' === $_fields ) {
   690 			$count = $wpdb->get_var( $this->request );
   722 			$count = $wpdb->get_var( $this->request );
   691 			wp_cache_set( $cache_key, $count, 'terms' );
   723 			wp_cache_set( $cache_key, $count, 'terms' );
   692 			return $count;
   724 			return $count;
   693 		}
   725 		}
   694 
   726 
   695 		$terms = $wpdb->get_results( $this->request );
   727 		$terms = $wpdb->get_results( $this->request );
   696 		if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) {
   728 
       
   729 		if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) {
   697 			update_term_cache( $terms );
   730 			update_term_cache( $terms );
   698 		}
   731 		}
   699 
   732 
   700 		// Prime termmeta cache.
   733 		// Prime termmeta cache.
   701 		if ( $args['update_term_meta_cache'] ) {
   734 		if ( $args['update_term_meta_cache'] ) {
   716 				}
   749 				}
   717 			}
   750 			}
   718 		}
   751 		}
   719 
   752 
   720 		// Update term counts to include children.
   753 		// Update term counts to include children.
   721 		if ( $args['pad_counts'] && 'all' == $_fields ) {
   754 		if ( $args['pad_counts'] && 'all' === $_fields ) {
   722 			foreach ( $taxonomies as $_tax ) {
   755 			foreach ( $taxonomies as $_tax ) {
   723 				_pad_term_counts( $terms, $_tax );
   756 				_pad_term_counts( $terms, $_tax );
   724 			}
   757 			}
   725 		}
   758 		}
   726 
   759 
   748 		 * When querying for terms connected to objects, we may get
   781 		 * When querying for terms connected to objects, we may get
   749 		 * duplicate results. The duplicates should be preserved if
   782 		 * duplicate results. The duplicates should be preserved if
   750 		 * `$fields` is 'all_with_object_id', but should otherwise be
   783 		 * `$fields` is 'all_with_object_id', but should otherwise be
   751 		 * removed.
   784 		 * removed.
   752 		 */
   785 		 */
   753 		if ( ! empty( $args['object_ids'] ) && 'all_with_object_id' != $_fields ) {
   786 		if ( ! empty( $args['object_ids'] ) && 'all_with_object_id' !== $_fields ) {
   754 			$_tt_ids = $_terms = array();
   787 			$_tt_ids = array();
       
   788 			$_terms  = array();
   755 			foreach ( $terms as $term ) {
   789 			foreach ( $terms as $term ) {
   756 				if ( isset( $_tt_ids[ $term->term_id ] ) ) {
   790 				if ( isset( $_tt_ids[ $term->term_id ] ) ) {
   757 					continue;
   791 					continue;
   758 				}
   792 				}
   759 
   793 
   763 
   797 
   764 			$terms = $_terms;
   798 			$terms = $_terms;
   765 		}
   799 		}
   766 
   800 
   767 		$_terms = array();
   801 		$_terms = array();
   768 		if ( 'id=>parent' == $_fields ) {
   802 		if ( 'id=>parent' === $_fields ) {
   769 			foreach ( $terms as $term ) {
   803 			foreach ( $terms as $term ) {
   770 				$_terms[ $term->term_id ] = $term->parent;
   804 				$_terms[ $term->term_id ] = $term->parent;
   771 			}
   805 			}
   772 		} elseif ( 'ids' == $_fields ) {
   806 		} elseif ( 'ids' === $_fields ) {
   773 			foreach ( $terms as $term ) {
   807 			foreach ( $terms as $term ) {
   774 				$_terms[] = (int) $term->term_id;
   808 				$_terms[] = (int) $term->term_id;
   775 			}
   809 			}
   776 		} elseif ( 'tt_ids' == $_fields ) {
   810 		} elseif ( 'tt_ids' === $_fields ) {
   777 			foreach ( $terms as $term ) {
   811 			foreach ( $terms as $term ) {
   778 				$_terms[] = (int) $term->term_taxonomy_id;
   812 				$_terms[] = (int) $term->term_taxonomy_id;
   779 			}
   813 			}
   780 		} elseif ( 'names' == $_fields ) {
   814 		} elseif ( 'names' === $_fields ) {
   781 			foreach ( $terms as $term ) {
   815 			foreach ( $terms as $term ) {
   782 				$_terms[] = $term->name;
   816 				$_terms[] = $term->name;
   783 			}
   817 			}
   784 		} elseif ( 'slugs' == $_fields ) {
   818 		} elseif ( 'slugs' === $_fields ) {
   785 			foreach ( $terms as $term ) {
   819 			foreach ( $terms as $term ) {
   786 				$_terms[] = $term->slug;
   820 				$_terms[] = $term->slug;
   787 			}
   821 			}
   788 		} elseif ( 'id=>name' == $_fields ) {
   822 		} elseif ( 'id=>name' === $_fields ) {
   789 			foreach ( $terms as $term ) {
   823 			foreach ( $terms as $term ) {
   790 				$_terms[ $term->term_id ] = $term->name;
   824 				$_terms[ $term->term_id ] = $term->name;
   791 			}
   825 			}
   792 		} elseif ( 'id=>slug' == $_fields ) {
   826 		} elseif ( 'id=>slug' === $_fields ) {
   793 			foreach ( $terms as $term ) {
   827 			foreach ( $terms as $term ) {
   794 				$_terms[ $term->term_id ] = $term->slug;
   828 				$_terms[ $term->term_id ] = $term->slug;
   795 			}
   829 			}
   796 		}
   830 		}
   797 
   831 
   836 			$orderby = "t.$_orderby";
   870 			$orderby = "t.$_orderby";
   837 		} elseif ( in_array( $_orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id', 'description' ), true ) ) {
   871 		} elseif ( in_array( $_orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id', 'description' ), true ) ) {
   838 			$orderby = "tt.$_orderby";
   872 			$orderby = "tt.$_orderby";
   839 		} elseif ( 'term_order' === $_orderby ) {
   873 		} elseif ( 'term_order' === $_orderby ) {
   840 			$orderby = 'tr.term_order';
   874 			$orderby = 'tr.term_order';
   841 		} elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) {
   875 		} elseif ( 'include' === $_orderby && ! empty( $this->query_vars['include'] ) ) {
   842 			$include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) );
   876 			$include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) );
   843 			$orderby = "FIELD( t.term_id, $include )";
   877 			$orderby = "FIELD( t.term_id, $include )";
   844 		} elseif ( 'slug__in' == $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) {
   878 		} elseif ( 'slug__in' === $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) {
   845 			$slugs   = implode( "', '", array_map( 'sanitize_title_for_query', $this->query_vars['slug'] ) );
   879 			$slugs   = implode( "', '", array_map( 'sanitize_title_for_query', $this->query_vars['slug'] ) );
   846 			$orderby = "FIELD( t.slug, '" . $slugs . "')";
   880 			$orderby = "FIELD( t.slug, '" . $slugs . "')";
   847 		} elseif ( 'none' == $_orderby ) {
   881 		} elseif ( 'none' === $_orderby ) {
   848 			$orderby = '';
   882 			$orderby = '';
   849 		} elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) {
   883 		} elseif ( empty( $_orderby ) || 'id' === $_orderby || 'term_id' === $_orderby ) {
   850 			$orderby = 't.term_id';
   884 			$orderby = 't.term_id';
   851 		} else {
   885 		} else {
   852 			$orderby = 't.name';
   886 			$orderby = 't.name';
   853 
   887 
   854 			// This may be a value of orderby related to meta.
   888 			// This may be a value of orderby related to meta.