Make WordPress Core


Ignore:
Timestamp:
01/18/2015 06:56:38 PM (9 years ago)
Author:
boonebgorges
Message:

Additional 'orderby' values for wp_get_object_terms().

Adds support for ordering by 'taxonomy', 'term_taxonomy_id', and 'parent'.

Props ChriCo.
Fixes #28688.

File:
1 edited

Legend:

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

    r31232 r31236  
    25632563 *     Array of arguments.
    25642564 *     @type string $orderby Field by which results should be sorted. Accepts 'name', 'count', 'slug', 'term_group',
    2565  *                           or 'term_order'. Default 'name'.
     2565 *                           'term_order', 'taxonomy', 'parent', or 'term_taxonomy_id'. Default 'name'.
    25662566 *     @type string $order   Sort order. Accepts 'ASC' or 'DESC'. Default 'ASC'.
    25672567 *     @type string $fields  Fields to return for matched terms. Accepts 'all', 'ids', 'names', and
     
    26132613    $fields = $args['fields'];
    26142614
    2615     if ( 'count' == $orderby ) {
    2616         $orderby = 'tt.count';
    2617     } elseif ( 'name' == $orderby ) {
    2618         $orderby = 't.name';
    2619     } elseif ( 'slug' == $orderby ) {
    2620         $orderby = 't.slug';
    2621     } elseif ( 'term_group' == $orderby ) {
    2622         $orderby = 't.term_group';
    2623     } elseif ( 'term_order' == $orderby ) {
     2615    if ( in_array( $orderby, array( 'term_id', 'name', 'slug', 'term_group' ) ) ) {
     2616        $orderby = "t.$orderby";
     2617    } else if ( in_array( $orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id' ) ) ) {
     2618        $orderby = "tt.$orderby";
     2619    } else if ( 'term_order' === $orderby ) {
    26242620        $orderby = 'tr.term_order';
    2625     } elseif ( 'none' == $orderby ) {
     2621    } else if ( 'none' === $orderby ) {
    26262622        $orderby = '';
    26272623        $order = '';
Note: See TracChangeset for help on using the changeset viewer.