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 ); + } }