WordPress.org

Make WordPress Core

Changeset 38500


Ignore:
Timestamp:
09/01/2016 04:50:47 PM (3 years ago)
Author:
boonebgorges
Message:

Query: 'orderby=include' should support comma-separated lists.

[30052] assumed that 'include' would be an array.

Props TimothyBlynJacobs.
Fixes #37904.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term-query.php

    r38377 r38500  
    774774            $orderby = 't.slug';
    775775        } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) {
    776             $include = implode( ',', array_map( 'absint', $this->query_vars['include'] ) );
     776            $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) );
    777777            $orderby = "FIELD( t.term_id, $include )";
    778778        } elseif ( 'term_group' == $_orderby ) {
  • trunk/tests/phpunit/tests/term/query.php

    r38211 r38500  
    166166        $this->assertNotEmpty( $q2->terms );
    167167    }
     168
     169    /**
     170     * @ticket 23261
     171     * @ticket 37904
     172     */
     173    public function test_orderby_include_with_comma_separated_list() {
     174        register_taxonomy( 'wptests_tax_1', 'post' );
     175
     176        $t1 = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax_1' ) );
     177        $t2 = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax_1' ) );
     178
     179        $query = new WP_Term_Query( array(
     180            'include' => "{$t1->term_id},{$t2->term_id}",
     181            'orderby' => 'include',
     182            'hide_empty' => false,
     183        ) );
     184        $terms = $query->get_terms();
     185
     186        $this->assertEquals( array( $t1, $t2 ), $terms );
     187    }
    168188}
Note: See TracChangeset for help on using the changeset viewer.