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:
parent
4d4f78ae97
commit
78df32df4e
@ -773,7 +773,7 @@ class WP_Term_Query {
|
|||||||
} elseif ( 'slug' == $_orderby ) {
|
} elseif ( 'slug' == $_orderby ) {
|
||||||
$orderby = 't.slug';
|
$orderby = 't.slug';
|
||||||
} elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) {
|
} 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 )";
|
$orderby = "FIELD( t.term_id, $include )";
|
||||||
} elseif ( 'term_group' == $_orderby ) {
|
} elseif ( 'term_group' == $_orderby ) {
|
||||||
$orderby = 't.term_group';
|
$orderby = 't.term_group';
|
||||||
|
@ -165,4 +165,24 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
|||||||
|
|
||||||
$this->assertNotEmpty( $q2->terms );
|
$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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user