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 |
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. |