Changeset 36691
- Timestamp:
- 02/24/2016 07:12:45 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r36634 r36691 1720 1720 } 1721 1721 1722 if ( $number && is_array( $terms ) && count( $terms ) > $number ) { 1723 $terms = array_slice( $terms, $offset, $number, true ); 1722 // Hierarchical queries are not limited, so 'offset' and 'number' must be handled now. 1723 if ( $hierarchical && $number && is_array( $terms ) ) { 1724 if ( $offset >= count( $terms ) ) { 1725 $terms = array(); 1726 } else { 1727 $terms = array_slice( $terms, $offset, $number, true ); 1728 } 1724 1729 } 1725 1730 -
trunk/tests/phpunit/tests/term/getTerms.php
r36614 r36691 2079 2079 } 2080 2080 2081 /** 2082 * @ticket 35935 2083 */ 2084 public function test_hierarchical_offset_0_with_number_greater_than_total_available_count() { 2085 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2086 2087 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2088 2089 $found = get_terms( 'wptests_tax', array( 2090 'number' => 3, 2091 'offset' => 0, 2092 'hide_empty' => false, 2093 'fields' => 'ids', 2094 ) ); 2095 $this->assertEqualSets( $terms, $found ); 2096 } 2097 2098 /** 2099 * @ticket 35935 2100 */ 2101 public function test_hierarchical_offset_plus_number() { 2102 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2103 2104 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); 2105 2106 $found = get_terms( 'wptests_tax', array( 2107 'number' => 1, 2108 'offset' => 1, 2109 'hide_empty' => false, 2110 'fields' => 'ids', 2111 'orderby' => 'term_id', 2112 'order' => 'ASC', 2113 ) ); 2114 $this->assertEqualSets( array( $terms[1] ), $found ); 2115 } 2116 2117 /** 2118 * @ticket 35935 2119 */ 2120 public function test_hierarchical_offset_plus_number_exceeds_available_count() { 2121 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2122 2123 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2124 2125 $found = get_terms( 'wptests_tax', array( 2126 'number' => 2, 2127 'offset' => 1, 2128 'hide_empty' => false, 2129 'fields' => 'ids', 2130 'orderby' => 'term_id', 2131 'order' => 'ASC', 2132 ) ); 2133 $this->assertEqualSets( array( $terms[1] ), $found ); 2134 } 2135 2136 /** 2137 * @ticket 35935 2138 */ 2139 public function test_hierarchical_offset_exceeds_available_count() { 2140 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2141 2142 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 2143 2144 $found = get_terms( 'wptests_tax', array( 2145 'number' => 100, 2146 'offset' => 3, 2147 'hide_empty' => false, 2148 'fields' => 'ids', 2149 'orderby' => 'term_id', 2150 'order' => 'ASC', 2151 ) ); 2152 $this->assertEqualSets( array(), $found ); 2153 } 2154 2081 2155 protected function create_hierarchical_terms_and_posts() { 2082 2156 $terms = array();
Note: See TracChangeset
for help on using the changeset viewer.