Make WordPress Core

Changeset 36057


Ignore:
Timestamp:
12/22/2015 01:52:41 AM (11 years ago)
Author:
boonebgorges
Message:

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.

Merges [36056] to the 4.4 branch.

Props afercia.
See #28922. Fixes #35180.

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/taxonomy.php

    r36004 r36057  
    36083608        $terms = wp_get_object_terms( $ids, $taxonomies, array(
    36093609                'fields' => 'all_with_object_id',
    3610                 'orderby' => 'none',
     3610                'orderby' => 'name',
    36113611                'update_term_meta_cache' => false,
    36123612        ) );
  • branches/4.4/tests/phpunit/tests/term.php

    r35851 r36057  
    618618
    619619        /**
     620         * @ticket 35180
     621         * @ticket 28922
     622         */
     623        public function test_get_the_terms_should_return_results_ordered_by_name_when_pulling_from_cache() {
     624                register_taxonomy( 'wptests_tax', 'post' );
     625                $p = self::$post_ids[0];
     626
     627                $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'fff' ) );
     628                $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'aaa' ) );
     629                $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'zzz' ) );
     630
     631                wp_set_object_terms( $p, array( $t1, $t2, $t3 ), 'wptests_tax' );
     632                update_object_term_cache( $p, 'post' );
     633
     634                $found = get_the_terms( $p, 'wptests_tax' );
     635
     636                $this->assertSame( array( $t2, $t1, $t3 ), wp_list_pluck( $found, 'term_id' ) );
     637        }
     638
     639        /**
    620640         * @ticket 19205
    621641         */
Note: See TracChangeset for help on using the changeset viewer.