Changeset 53496
- Timestamp:
- 06/14/2022 11:41:33 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-term-query.php
r53469 r53496 771 771 $cache_args = wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ); 772 772 773 unset( $cache_args[' pad_counts'], $cache_args['update_term_meta_cache'] );773 unset( $cache_args['update_term_meta_cache'] ); 774 774 775 775 if ( 'count' !== $_fields && 'all_with_object_id' !== $_fields ) { … … 784 784 if ( false !== $cache ) { 785 785 if ( 'ids' === $_fields ) { 786 $term_ids = wp_list_pluck( $cache, 'term_id' ); 787 $cache = array_map( 'intval', $term_ids ); 786 $cache = array_map( 'intval', $cache ); 788 787 } elseif ( 'count' !== $_fields ) { 789 $term_ids = wp_list_pluck( $cache, 'term_id' ); 788 if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) || ( 'all' === $_fields && $args['pad_counts'] ) ) { 789 $term_ids = wp_list_pluck( $cache, 'term_id' ); 790 } else { 791 $term_ids = array_map( 'intval', $cache ); 792 } 790 793 _prime_term_caches( $term_ids, $args['update_term_meta_cache'] ); 791 794 $term_objects = $this->populate_terms( $cache ); … … 850 853 } 851 854 852 /*853 * When querying for terms connected to objects, we may get854 * duplicate results. The duplicates should be preserved if855 * `$fields` is 'all_with_object_id', but should otherwise be856 * removed.857 */858 if ( ! empty( $args['object_ids'] ) && 'all_with_object_id' !== $_fields ) {859 $_tt_ids = array();860 $_terms = array();861 foreach ( $terms as $term ) {862 if ( isset( $_tt_ids[ $term->term_id ] ) ) {863 continue;864 }865 866 $_tt_ids[ $term->term_id ] = 1;867 $_terms[] = $term;868 }869 870 $terms = $_terms;871 }872 873 855 // Hierarchical queries are not limited, so 'offset' and 'number' must be handled now. 874 if ( $hierarchical && $number && is_array( $terms ) ) { 875 if ( $offset >= count( $terms ) ) { 876 $terms = array(); 856 if ( $hierarchical && $number && is_array( $term_objects ) ) { 857 if ( $offset >= count( $term_objects ) ) { 877 858 $term_objects = array(); 878 859 } else { 879 $terms = array_slice( $terms, $offset, $number, true );880 860 $term_objects = array_slice( $term_objects, $offset, $number, true ); 881 861 } … … 888 868 } 889 869 890 wp_cache_add( $cache_key, $terms, 'terms' ); 891 $terms = $this->format_terms( $term_objects, $_fields ); 892 893 $this->terms = $terms; 870 if ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) { 871 $term_cache = array(); 872 foreach ( $term_objects as $term ) { 873 $object = new stdClass(); 874 $object->term_id = $term->term_id; 875 $object->object_id = $term->object_id; 876 $term_cache[] = $object; 877 } 878 } elseif ( 'all' === $_fields && $args['pad_counts'] ) { 879 $term_cache = array(); 880 foreach ( $term_objects as $term ) { 881 $object = new stdClass(); 882 $object->term_id = $term->term_id; 883 $object->count = $term->count; 884 $term_cache[] = $object; 885 } 886 } else { 887 $term_cache = wp_list_pluck( $term_objects, 'term_id' ); 888 } 889 wp_cache_add( $cache_key, $term_cache, 'terms' ); 890 $this->terms = $this->format_terms( $term_objects, $_fields ); 891 894 892 return $this->terms; 895 893 } … … 1120 1118 $term->object_id = (int) $term_data->object_id; 1121 1119 } 1120 1121 1122 1122 1123 } else { 1123 1124 $term = get_term( $term_data ); -
trunk/src/wp-includes/version.php
r53344 r53496 24 24 * @global int $wp_db_version 25 25 */ 26 $wp_db_version = 5 1917;26 $wp_db_version = 5; 27 27 28 28 /** -
trunk/tests/phpunit/tests/term/getTerms.php
r53309 r53496 745 745 ); 746 746 $this->assertCount( 1, $terms ); 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 747 768 } 748 769 … … 2591 2612 2592 2613 /** 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2593 2684 * @ticket 20635 2594 2685 */ … … 3098 3189 'taxonomy' => self::$taxonomy, 3099 3190 'fields' => 'slugs', 3100 ),3101 ),3102 'meta cache off, pad count on vs meta cache on, pad count off' => array(3103 array(3104 'taxonomy' => self::$taxonomy,3105 'pad_counts' => true,3106 'update_term_meta_cache' => false,3107 ),3108 array(3109 'taxonomy' => self::$taxonomy,3110 'fields' => 'ids',3111 3191 ), 3112 3192 ),
Note: See TracChangeset
for help on using the changeset viewer.