diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 42164528fc..a1d6e04686 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -3609,7 +3609,7 @@ function update_object_term_cache($object_ids, $object_type) { $terms = wp_get_object_terms( $ids, $taxonomies, array( 'fields' => 'all_with_object_id', - 'orderby' => 'none', + 'orderby' => 'name', 'update_term_meta_cache' => false, ) ); diff --git a/tests/phpunit/tests/term.php b/tests/phpunit/tests/term.php index 9c6e9655a4..1fdbd14825 100644 --- a/tests/phpunit/tests/term.php +++ b/tests/phpunit/tests/term.php @@ -616,6 +616,26 @@ class Tests_Term extends WP_UnitTestCase { $this->assertEqualSets( array( 0, 1 ), array_keys( $found ) ); } + /** + * @ticket 35180 + * @ticket 28922 + */ + public function test_get_the_terms_should_return_results_ordered_by_name_when_pulling_from_cache() { + register_taxonomy( 'wptests_tax', 'post' ); + $p = self::$post_ids[0]; + + $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'fff' ) ); + $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'aaa' ) ); + $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'zzz' ) ); + + wp_set_object_terms( $p, array( $t1, $t2, $t3 ), 'wptests_tax' ); + update_object_term_cache( $p, 'post' ); + + $found = get_the_terms( $p, 'wptests_tax' ); + + $this->assertSame( array( $t2, $t1, $t3 ), wp_list_pluck( $found, 'term_id' ) ); + } + /** * @ticket 19205 */