Changeset 56585 for trunk/src/wp-includes/class-wp-term-query.php
- Timestamp:
- 09/14/2023 12:38:04 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-term-query.php
r56555 r56585 92 92 * @since 5.1.0 Introduced the 'meta_compare_key' parameter. 93 93 * @since 5.3.0 Introduced the 'meta_type_key' parameter. 94 * @since 6.4.0 Introduced the 'cache_results' parameter. 94 95 * 95 96 * @param string|array $query { … … 179 180 * @type string $cache_domain Unique cache key to be produced when this query is stored in 180 181 * an object cache. Default 'core'. 182 * @type bool $cache_results Whether to cache term information. Default true. 181 183 * @type bool $update_term_meta_cache Whether to prime meta caches for matched terms. Default true. 182 184 * @type string|string[] $meta_key Meta key or keys to filter by. … … 221 223 'childless' => false, 222 224 'cache_domain' => 'core', 225 'cache_results' => true, 223 226 'update_term_meta_cache' => true, 224 227 'meta_query' => '', … … 777 780 } 778 781 779 $cache_key = $this->generate_cache_key( $args, $this->request ); 780 $cache = wp_cache_get( $cache_key, 'term-queries' ); 781 782 if ( false !== $cache ) { 783 if ( 'ids' === $_fields ) { 784 $cache = array_map( 'intval', $cache ); 785 } elseif ( 'count' !== $_fields ) { 786 if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) 782 if ( $args['cache_results'] ) { 783 $cache_key = $this->generate_cache_key( $args, $this->request ); 784 $cache = wp_cache_get( $cache_key, 'term-queries' ); 785 786 if ( false !== $cache ) { 787 if ( 'ids' === $_fields ) { 788 $cache = array_map( 'intval', $cache ); 789 } elseif ( 'count' !== $_fields ) { 790 if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) 787 791 || ( 'all' === $_fields && $args['pad_counts'] || $fields_is_filtered ) 788 ) { 789 $term_ids = wp_list_pluck( $cache, 'term_id' ); 790 } else { 791 $term_ids = array_map( 'intval', $cache ); 792 ) { 793 $term_ids = wp_list_pluck( $cache, 'term_id' ); 794 } else { 795 $term_ids = array_map( 'intval', $cache ); 796 } 797 798 _prime_term_caches( $term_ids, $args['update_term_meta_cache'] ); 799 800 $term_objects = $this->populate_terms( $cache ); 801 $cache = $this->format_terms( $term_objects, $_fields ); 792 802 } 793 803 794 _prime_term_caches( $term_ids, $args['update_term_meta_cache'] ); 795 796 $term_objects = $this->populate_terms( $cache ); 797 $cache = $this->format_terms( $term_objects, $_fields ); 798 } 799 800 $this->terms = $cache; 801 return $this->terms; 804 $this->terms = $cache; 805 return $this->terms; 806 } 802 807 } 803 808 804 809 if ( 'count' === $_fields ) { 805 810 $count = $wpdb->get_var( $this->request ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 806 wp_cache_set( $cache_key, $count, 'term-queries' ); 811 if ( $args['cache_results'] ) { 812 wp_cache_set( $cache_key, $count, 'term-queries' ); 813 } 807 814 return $count; 808 815 } … … 811 818 812 819 if ( empty( $terms ) ) { 813 wp_cache_add( $cache_key, array(), 'term-queries' ); 820 if ( $args['cache_results'] ) { 821 wp_cache_add( $cache_key, array(), 'term-queries' ); 822 } 814 823 return array(); 815 824 } … … 893 902 } 894 903 895 wp_cache_add( $cache_key, $term_cache, 'term-queries' ); 904 if ( $args['cache_results'] ) { 905 wp_cache_add( $cache_key, $term_cache, 'term-queries' ); 906 } 907 896 908 $this->terms = $this->format_terms( $term_objects, $_fields ); 897 909 … … 1154 1166 $cache_args = wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ); 1155 1167 1156 unset( $cache_args[' update_term_meta_cache'] );1168 unset( $cache_args['cache_results'], $cache_args['update_term_meta_cache'] ); 1157 1169 1158 1170 if ( 'count' !== $args['fields'] && 'all_with_object_id' !== $args['fields'] ) {
Note: See TracChangeset
for help on using the changeset viewer.