Order terms by 'name' when populating object term cache.

[34217] removed the `ORDER BY` clause from `update_object_term_cache()`, for
improved performance. But this proved to cause problems in cases where users
were expecting the results of `get_the_terms()` to be ordered by 'name'. Let's
revert the change for the time being, and look into more disciplined ordering
in a future release.

Props afercia.
See #28922. Fixes #35180.

git-svn-id: https://develop.svn.wordpress.org/trunk@36056 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-12-22 01:50:08 +00:00
parent d303221d08
commit 1bf73525e8
2 changed files with 21 additions and 1 deletions

View File

@ -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,
) );

View File

@ -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
*/