equal
deleted
inserted
replaced
146 * - 'id=>name' Returns an associative array of term names, |
146 * - 'id=>name' Returns an associative array of term names, |
147 * keyed by term ID (`string[]`). |
147 * keyed by term ID (`string[]`). |
148 * - 'id=>slug' Returns an associative array of term slugs, |
148 * - 'id=>slug' Returns an associative array of term slugs, |
149 * keyed by term ID (`string[]`). |
149 * keyed by term ID (`string[]`). |
150 * Default 'all'. |
150 * Default 'all'. |
151 * @type bool $count Whether to return a term count. If true, will take precedence |
|
152 * over `$fields`. Default false. |
|
153 * @type string|string[] $name Name or array of names to return term(s) for. |
151 * @type string|string[] $name Name or array of names to return term(s) for. |
154 * Default empty. |
152 * Default empty. |
155 * @type string|string[] $slug Slug or array of slugs to return term(s) for. |
153 * @type string|string[] $slug Slug or array of slugs to return term(s) for. |
156 * Default empty. |
154 * Default empty. |
157 * @type int|int[] $term_taxonomy_id Term taxonomy ID, or array of term taxonomy IDs, |
155 * @type int|int[] $term_taxonomy_id Term taxonomy ID, or array of term taxonomy IDs, |
206 'exclude' => array(), |
204 'exclude' => array(), |
207 'exclude_tree' => array(), |
205 'exclude_tree' => array(), |
208 'number' => '', |
206 'number' => '', |
209 'offset' => '', |
207 'offset' => '', |
210 'fields' => 'all', |
208 'fields' => 'all', |
211 'count' => false, |
|
212 'name' => '', |
209 'name' => '', |
213 'slug' => '', |
210 'slug' => '', |
214 'term_taxonomy_id' => '', |
211 'term_taxonomy_id' => '', |
215 'hierarchical' => true, |
212 'hierarchical' => true, |
216 'search' => '', |
213 'search' => '', |
302 * |
299 * |
303 * @since 4.6.0 |
300 * @since 4.6.0 |
304 * |
301 * |
305 * @param string|array $query Array or URL query string of parameters. |
302 * @param string|array $query Array or URL query string of parameters. |
306 * @return WP_Term[]|int[]|string[]|string Array of terms, or number of terms as numeric string |
303 * @return WP_Term[]|int[]|string[]|string Array of terms, or number of terms as numeric string |
307 * when 'count' is passed as a query var. |
304 * when 'count' is passed to `$args['fields']`. |
308 */ |
305 */ |
309 public function query( $query ) { |
306 public function query( $query ) { |
310 $this->query_vars = wp_parse_args( $query ); |
307 $this->query_vars = wp_parse_args( $query ); |
311 return $this->get_terms(); |
308 return $this->get_terms(); |
312 } |
309 } |
344 * @since 4.6.0 |
341 * @since 4.6.0 |
345 * |
342 * |
346 * @global wpdb $wpdb WordPress database abstraction object. |
343 * @global wpdb $wpdb WordPress database abstraction object. |
347 * |
344 * |
348 * @return WP_Term[]|int[]|string[]|string Array of terms, or number of terms as numeric string |
345 * @return WP_Term[]|int[]|string[]|string Array of terms, or number of terms as numeric string |
349 * when 'count' is passed as a query var. |
346 * when 'count' is passed to `$args['fields']`. |
350 */ |
347 */ |
351 public function get_terms() { |
348 public function get_terms() { |
352 global $wpdb; |
349 global $wpdb; |
353 |
350 |
354 $this->parse_query( $this->query_vars ); |
351 $this->parse_query( $this->query_vars ); |
1168 unset( $cache_args['cache_results'], $cache_args['update_term_meta_cache'] ); |
1165 unset( $cache_args['cache_results'], $cache_args['update_term_meta_cache'] ); |
1169 |
1166 |
1170 if ( 'count' !== $args['fields'] && 'all_with_object_id' !== $args['fields'] ) { |
1167 if ( 'count' !== $args['fields'] && 'all_with_object_id' !== $args['fields'] ) { |
1171 $cache_args['fields'] = 'all'; |
1168 $cache_args['fields'] = 'all'; |
1172 } |
1169 } |
1173 $taxonomies = (array) $args['taxonomy']; |
|
1174 |
1170 |
1175 // Replace wpdb placeholder in the SQL statement used by the cache key. |
1171 // Replace wpdb placeholder in the SQL statement used by the cache key. |
1176 $sql = $wpdb->remove_placeholder_escape( $sql ); |
1172 $sql = $wpdb->remove_placeholder_escape( $sql ); |
1177 |
1173 |
1178 $key = md5( serialize( $cache_args ) . serialize( $taxonomies ) . $sql ); |
1174 $key = md5( serialize( $cache_args ) . $sql ); |
1179 $last_changed = wp_cache_get_last_changed( 'terms' ); |
1175 $last_changed = wp_cache_get_last_changed( 'terms' ); |
1180 return "get_terms:$key:$last_changed"; |
1176 return "get_terms:$key:$last_changed"; |
1181 } |
1177 } |
1182 } |
1178 } |