Make WordPress Core

Changeset 31532


Ignore:
Timestamp:
02/24/2015 04:36:26 PM (10 years ago)
Author:
boonebgorges
Message:

Add 'orderby=description' support to get_terms().

This fixes an interface inconsistency in edit-tags.php, where Description
appears as a sortable column header.

Props neil_pie.
Fixes #31364.

Location:
trunk
Files:
2 edited

Legend:

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

    r31525 r31532  
    15751575 *     Optional. Array or string of arguments to get terms.
    15761576 *
    1577  *     @type string   $orderby               Field(s) to order terms by. Accepts term fields ('name', 'slug',
    1578  *                                           'term_group', 'term_id', 'id'), 'count' for term taxonomy count,
    1579  *                                           'include' to match the 'order' of the $include param, or 'none'
    1580  *                                           to skip ORDER BY. Defaults to 'name'.
    1581  *     @type string   $order                 Whether to order terms in ascending or descending order.
     1577 *     @type string       $orderby           Field(s) to order terms by. Accepts term fields ('name', 'slug',
     1578 *                                           'term_group', 'term_id', 'id', 'description'), 'count' for term
     1579 *                                           taxonomy count, 'include' to match the 'order' of the $include param,
     1580 *                                           or 'none' to skip ORDER BY. Defaults to 'name'.
     1581 *     @type string       $order             Whether to order terms in ascending or descending order.
    15821582 *                                           Accepts 'ASC' (ascending) or 'DESC' (descending).
    15831583 *                                           Default 'ASC'.
     
    17481748    } elseif ( 'term_group' == $_orderby ) {
    17491749        $orderby = 't.term_group';
     1750    } elseif ( 'description' == $_orderby ) {
     1751        $orderby = 'tt.description';
    17501752    } elseif ( 'none' == $_orderby ) {
    17511753        $orderby = '';
  • trunk/tests/phpunit/tests/term/getTerms.php

    r31285 r31532  
    11361136    }
    11371137
     1138    /**
     1139     * @ticket 31364
     1140     */
     1141    public function test_orderby_description() {
     1142        $tax = 'wptests_tax';
     1143        register_taxonomy( $tax, 'post' );
     1144
     1145        $t1 = $this->factory->term->create( array( 'taxonomy' => $tax, 'description' => 'fff' ) );
     1146        $t2 = $this->factory->term->create( array( 'taxonomy' => $tax, 'description' => 'aaa' ) );
     1147        $t3 = $this->factory->term->create( array( 'taxonomy' => $tax, 'description' => 'zzz' ) );
     1148        $t4 = $this->factory->term->create( array( 'taxonomy' => $tax, 'description' => 'jjj' ) );
     1149
     1150        $found = get_terms( $tax, array(
     1151            'fields' => 'ids',
     1152            'orderby' => 'description',
     1153            'hide_empty' => false,
     1154        ) );
     1155
     1156        _unregister_taxonomy( 'wptests_tax' );
     1157
     1158        $this->assertEquals( array( $t2, $t1, $t4, $t3 ), $found );
     1159    }
     1160
    11381161    public function test_hierarchical_false_with_parent() {
    11391162        $initial_terms = $this->create_hierarchical_terms();
Note: See TracChangeset for help on using the changeset viewer.