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

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

Props TimothyBlynJacobs.
Fixes #37904.

git-svn-id: https://develop.svn.wordpress.org/trunk@38500 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-09-01 16:50:47 +00:00
parent 4d4f78ae97
commit 78df32df4e
2 changed files with 21 additions and 1 deletions

View File

@ -773,7 +773,7 @@ class WP_Term_Query {
} elseif ( 'slug' == $_orderby ) {
$orderby = 't.slug';
} elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) {
$include = implode( ',', array_map( 'absint', $this->query_vars['include'] ) );
$include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) );
$orderby = "FIELD( t.term_id, $include )";
} elseif ( 'term_group' == $_orderby ) {
$orderby = 't.term_group';

View File

@ -165,4 +165,24 @@ class Tests_Term_Query extends WP_UnitTestCase {
$this->assertNotEmpty( $q2->terms );
}
/**
* @ticket 23261
* @ticket 37904
*/
public function test_orderby_include_with_comma_separated_list() {
register_taxonomy( 'wptests_tax_1', 'post' );
$t1 = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax_1' ) );
$t2 = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax_1' ) );
$query = new WP_Term_Query( array(
'include' => "{$t1->term_id},{$t2->term_id}",
'orderby' => 'include',
'hide_empty' => false,
) );
$terms = $query->get_terms();
$this->assertEquals( array( $t1, $t2 ), $terms );
}
}