mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
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:
64
tests/phpunit/tests/term/query.php
Normal file
64
tests/phpunit/tests/term/query.php
Normal 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 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user