mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
Restore support for taxonomy 'args' override when querying object terms.
[7520] introduced an undocumented feature whereby developers could register a custom taxonomy with an 'args' parameter, consisting of an array of config params that, when present, override corresponding params in the `$args` array passed to `wp_get_object_terms()` when using that function to query for terms in the specified taxonomy. The `wp_get_object_terms()` refactor in [38667] failed to respect this secret covenant, and the current changeset atones for the transgression. Props danielbachhuber. Fixes #40496. git-svn-id: https://develop.svn.wordpress.org/trunk@40513 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -381,4 +381,50 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
$count = $query->get_terms();
|
||||
$this->assertEquals( 1, $count );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40496
|
||||
*/
|
||||
public function test_get_the_terms_should_respect_taxonomy_orderby() {
|
||||
register_taxonomy( 'wptests_tax', 'post', array(
|
||||
'sort' => true,
|
||||
'args' => array(
|
||||
'orderby' => 'term_order',
|
||||
),
|
||||
) );
|
||||
$term_ids = self::factory()->term->create_many( 2, array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
) );
|
||||
$post_id = self::factory()->post->create();
|
||||
wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' );
|
||||
$terms = get_the_terms( $post_id, 'wptests_tax' );
|
||||
$this->assertEquals( array( $term_ids[0], $term_ids[1] ), wp_list_pluck( $terms, 'term_id' ) );
|
||||
// Flip the order
|
||||
wp_set_object_terms( $post_id, array( $term_ids[1], $term_ids[0] ), 'wptests_tax' );
|
||||
$terms = get_the_terms( $post_id, 'wptests_tax' );
|
||||
$this->assertEquals( array( $term_ids[1], $term_ids[0] ), wp_list_pluck( $terms, 'term_id' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40496
|
||||
*/
|
||||
public function test_wp_get_object_terms_should_respect_taxonomy_orderby() {
|
||||
register_taxonomy( 'wptests_tax', 'post', array(
|
||||
'sort' => true,
|
||||
'args' => array(
|
||||
'orderby' => 'term_order',
|
||||
),
|
||||
) );
|
||||
$term_ids = self::factory()->term->create_many( 2, array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
) );
|
||||
$post_id = self::factory()->post->create();
|
||||
wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' );
|
||||
$terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) );
|
||||
$this->assertEquals( array( $term_ids[0], $term_ids[1], 1 ), wp_list_pluck( $terms, 'term_id' ) );
|
||||
// Flip the order
|
||||
wp_set_object_terms( $post_id, array( $term_ids[1], $term_ids[0] ), 'wptests_tax' );
|
||||
$terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) );
|
||||
$this->assertEquals( array( $term_ids[1], $term_ids[0], 1 ), wp_list_pluck( $terms, 'term_id' ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user