Introduce term_taxonomy_id parameter for WP_Term_Query.

Allows the fetching of terms based on `term_taxonomy_id`, or an array of
`term_taxonomy_ids`.

Props spacedmonkey.
Fixes #37074.

git-svn-id: https://develop.svn.wordpress.org/trunk@37683 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-06-11 03:48:03 +00:00
parent beebded867
commit b9d46425c0
2 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
/**
* @group taxonomy
*/
class Tests_Term_Query extends WP_UnitTestCase {
/**
* @ticket 37074
*/
public function test_term_taxonomy_id_single() {
global $wpdb;
register_taxonomy( 'wptests_tax', 'post' );
$terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
// Manually change the term_taxonomy_id to something else.
$wpdb->update(
$wpdb->term_taxonomy,
array( 'term_taxonomy_id' => 12345 ),
array( 'term_id' => $terms[0] )
);
$q = new WP_Term_Query( array(
'term_taxonomy_id' => 12345,
'fields' => 'ids',
'hide_empty' => false,
) );
$this->assertEqualSets( array( $terms[0] ), $q->terms );
}
/**
* @ticket 37074
*/
public function test_term_taxonomy_id_array() {
global $wpdb;
register_taxonomy( 'wptests_tax', 'post' );
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
// Manually change the term_taxonomy_id to something else.
$wpdb->update(
$wpdb->term_taxonomy,
array( 'term_taxonomy_id' => 12345 ),
array( 'term_id' => $terms[0] )
);
$wpdb->update(
$wpdb->term_taxonomy,
array( 'term_taxonomy_id' => 6789 ),
array( 'term_id' => $terms[2] )
);
$q = new WP_Term_Query( array(
'term_taxonomy_id' => array( 12345, 6789 ),
'fields' => 'ids',
'hide_empty' => false,
) );
$this->assertEqualSets( array( $terms[0], $terms[2] ), $q->terms );
}
}