mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Don't reset index keys when trimming results of term queries.
`array_slice()` must be told to preserve keys when the query results exceed the limit specified the 'number' parameter, so that `id=>parent` and other id-indexed return value formats don't get mangled. Props fantasyworld, wpdelighter. Fixes #35382. git-svn-id: https://develop.svn.wordpress.org/trunk@36252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1604,7 +1604,7 @@ function get_terms( $taxonomies, $args = '' ) {
|
||||
}
|
||||
|
||||
if ( $number && is_array( $terms ) && count( $terms ) > $number ) {
|
||||
$terms = array_slice( $terms, $offset, $number );
|
||||
$terms = array_slice( $terms, $offset, $number, true );
|
||||
}
|
||||
|
||||
wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS );
|
||||
|
||||
@@ -1665,6 +1665,25 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35382
|
||||
*/
|
||||
public function test_indexes_should_not_be_reset_when_number_of_matched_terms_is_greater_than_number() {
|
||||
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$found = get_terms( 'wptests_tax', array(
|
||||
'hide_empty' => false,
|
||||
'fields' => 'id=>parent',
|
||||
'number' => 2,
|
||||
'orderby' => 'id',
|
||||
'order' => 'ASC',
|
||||
'hierarchical' => true,
|
||||
) );
|
||||
|
||||
$this->assertSame( array( $terms[0], $terms[1] ), array_keys( $found ) );
|
||||
}
|
||||
|
||||
protected function create_hierarchical_terms_and_posts() {
|
||||
$terms = array();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user