In `WP_Term_Query`, accept a string value for `taxonomy`.

Props endocreative.
Props ocean90 for review.
Fixes #37545.

git-svn-id: https://develop.svn.wordpress.org/trunk@38181 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-08-03 13:50:14 +00:00
parent 6efa061bd5
commit fa21c5e675
2 changed files with 36 additions and 1 deletions

View File

@ -219,7 +219,7 @@ class WP_Term_Query {
$query = $this->query_vars;
}
$taxonomies = isset( $query['taxonomy'] ) ? $query['taxonomy'] : null;
$taxonomies = isset( $query['taxonomy'] ) ? (array) $query['taxonomy'] : null;
/**
* Filters the terms query default arguments.

View File

@ -4,6 +4,41 @@
* @group taxonomy
*/
class Tests_Term_Query extends WP_UnitTestCase {
/**
* @ticket 37545
*/
public function test_taxonomy_should_accept_single_taxonomy_as_string() {
register_taxonomy( 'wptests_tax_1', 'post' );
register_taxonomy( 'wptests_tax_2', 'post' );
$term_1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
$term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) );
$q = new WP_Term_Query( array(
'taxonomy' => 'wptests_tax_2',
'fields' => 'ids',
'hide_empty' => false,
) );
$this->assertEqualSets( array( $term_2 ), $q->terms );
}
public function test_taxonomy_should_accept_taxonomy_array() {
register_taxonomy( 'wptests_tax_1', 'post' );
register_taxonomy( 'wptests_tax_2', 'post' );
$term_1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
$term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) );
$q = new WP_Term_Query( array(
'taxonomy' => array( 'wptests_tax_2' ),
'fields' => 'ids',
'hide_empty' => false,
) );
$this->assertEqualSets( array( $term_2 ), $q->terms );
}
/**
* @ticket 37074
*/