WordPress.org

Make WordPress Core

Changeset 30052


Ignore:
Timestamp:
10/28/2014 06:12:30 PM (5 years ago)
Author:
boonebgorges
Message:

Introduce orderby=include support for get_terms().

Props wpsmith.
Fixes #23261.

Location:
trunk
Files:
2 edited

Legend:

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

    r30042 r30052  
    17131713    } else if ( 'slug' == $_orderby ) {
    17141714        $orderby = 't.slug';
     1715    } else if ( 'include' == $_orderby && ! empty( $args['include'] ) ) {
     1716        $include = implode( ',', array_map( 'absint', $args['include'] ) );
     1717        $orderby = "FIELD( t.term_id, $include )";
    17151718    } else if ( 'term_group' == $_orderby ) {
    17161719        $orderby = 't.term_group';
  • trunk/tests/phpunit/tests/term/getTerms.php

    r30042 r30052  
    797797    }
    798798
     799    /**
     800     * @ticket 23261
     801     */
     802    public function test_orderby_include() {
     803        $tax = 'wptests_tax';
     804        register_taxonomy( $tax, 'post' );
     805
     806        $t1 = $this->factory->term->create( array( 'taxonomy' => $tax ) );
     807        $t2 = $this->factory->term->create( array( 'taxonomy' => $tax ) );
     808        $t3 = $this->factory->term->create( array( 'taxonomy' => $tax ) );
     809        $t4 = $this->factory->term->create( array( 'taxonomy' => $tax ) );
     810
     811        $found = get_terms( $tax, array(
     812            'fields' => 'ids',
     813            'include' => array( $t4, $t1, $t2 ),
     814            'orderby' => 'include',
     815            'hide_empty' => false,
     816        ) );
     817
     818        _unregister_taxonomy( 'wptests_tax' );
     819
     820        $this->assertEquals( array( $t4, $t1, $t2 ), $found );
     821    }
     822
    799823    protected function create_hierarchical_terms_and_posts() {
    800824
Note: See TracChangeset for help on using the changeset viewer.