From 78df32df4e3812ca49cfd474f49b1e77e0c009f8 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 1 Sep 2016 16:50:47 +0000 Subject: [PATCH] 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 --- src/wp-includes/class-wp-term-query.php | 2 +- tests/phpunit/tests/term/query.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 53be3c3df7..338c940255 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -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'; diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 2445741d47..a70bfd51c9 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -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 ); + } }