Changeset 31248
- Timestamp:
- 01/19/2015 04:51:44 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r31238 r31248 3921 3921 3922 3922 // Touch every ancestor's lookup row for each post in each term 3923 $ancestors = array();3924 3923 foreach ( $term_ids as $term_id ) { 3925 $ancestors[] = $term_id;3926 3924 $child = $term_id; 3925 $ancestors = array(); 3927 3926 while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) { 3928 if ( in_array( $parent, $ancestors ) ) { 3929 break; 3930 } 3931 3927 $ancestors[] = $child; 3932 3928 if ( !empty( $term_items[$term_id] ) ) 3933 3929 foreach ( $term_items[$term_id] as $item_id => $touches ) { … … 3935 3931 } 3936 3932 $child = $parent; 3933 3934 if ( in_array( $parent, $ancestors ) ) { 3935 break; 3936 } 3937 3937 } 3938 3938 } -
trunk/tests/phpunit/tests/term/getTerms.php
r31207 r31248 1078 1078 } 1079 1079 1080 /* 1080 public function test_pad_counts() { 1081 register_taxonomy( 'wptests_tax_1', 'post', array( 'hierarchical' => true ) ); 1082 1083 $posts = $this->factory->post->create_many( 3 ); 1084 1085 $t1 = $this->factory->term->create( array( 1086 'taxonomy' => 'wptests_tax_1', 1087 ) ); 1088 $t2 = $this->factory->term->create( array( 1089 'taxonomy' => 'wptests_tax_1', 1090 'parent' => $t1, 1091 ) ); 1092 $t3 = $this->factory->term->create( array( 1093 'taxonomy' => 'wptests_tax_1', 1094 'parent' => $t2, 1095 ) ); 1096 1097 wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax_1' ); 1098 wp_set_object_terms( $posts[1], array( $t2 ), 'wptests_tax_1' ); 1099 wp_set_object_terms( $posts[2], array( $t3 ), 'wptests_tax_1' ); 1100 1101 $found = get_terms( 'wptests_tax_1', array( 1102 'pad_counts' => true, 1103 ) ); 1104 1105 $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) ); 1106 1107 foreach ( $found as $f ) { 1108 if ( $t1 == $f->term_id ) { 1109 $this->assertSame( 3, $f->count ); 1110 } elseif ( $t2 == $f->term_id ) { 1111 $this->assertSame( 2, $f->count ); 1112 } else { 1113 $this->assertSame( 1, $f->count ); 1114 } 1115 } 1116 } 1117 1118 /** 1081 1119 * @ticket 20635 1082 1120 */ … … 1101 1139 1102 1140 $this->assertEqualSets( array( $c1, $c2, $c3 ), wp_list_pluck( $terms, 'term_id' ) ); 1141 1142 foreach ( $terms as $term ) { 1143 $this->assertSame( 3, $term->count ); 1144 } 1103 1145 } 1104 1146
Note: See TracChangeset
for help on using the changeset viewer.