WordPress.org

Make WordPress Core

Changeset 36056 for trunk


Ignore:
Timestamp:
12/22/2015 01:50:08 AM (4 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.

Props afercia.
See #28922. Fixes #35180.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r36003 r36056  
    36103610    $terms = wp_get_object_terms( $ids, $taxonomies, array(
    36113611        'fields' => 'all_with_object_id',
    3612         'orderby' => 'none',
     3612        'orderby' => 'name',
    36133613        'update_term_meta_cache' => false,
    36143614    ) );
  • trunk/tests/phpunit/tests/term.php

    r35850 r36056  
    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.