Changeset 40514
- Timestamp:
- 04/21/2017 07:18:00 PM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-includes/taxonomy.php
r40354 r40514 1874 1874 $args = wp_parse_args( $args ); 1875 1875 1876 /* 1877 * When one or more queried taxonomies is registered with an 'args' array, 1878 * those params override the `$args` passed to this function. 1879 */ 1880 $terms = array(); 1881 if ( count( $taxonomies ) > 1 ) { 1882 foreach ( $taxonomies as $index => $taxonomy ) { 1883 $t = get_taxonomy( $taxonomy ); 1884 if ( isset( $t->args ) && is_array( $t->args ) && $args != array_merge( $args, $t->args ) ) { 1885 unset( $taxonomies[ $index ] ); 1886 $terms = array_merge( $terms, wp_get_object_terms( $object_ids, $taxonomy, array_merge( $args, $t->args ) ) ); 1887 } 1888 } 1889 } else { 1890 $t = get_taxonomy( $taxonomies[0] ); 1891 if ( isset( $t->args ) && is_array( $t->args ) ) { 1892 $args = array_merge( $args, $t->args ); 1893 } 1894 } 1895 1876 1896 $args['taxonomy'] = $taxonomies; 1877 1897 $args['object_ids'] = $object_ids; 1878 1898 1879 $terms = get_terms( $args);1899 $terms = array_merge( $terms, get_terms( $args ) ); 1880 1900 1881 1901 /** -
branches/4.7/tests/phpunit/tests/term/query.php
r38784 r40514 382 382 $this->assertEquals( 1, $count ); 383 383 } 384 385 /** 386 * @ticket 40496 387 */ 388 public function test_get_the_terms_should_respect_taxonomy_orderby() { 389 register_taxonomy( 'wptests_tax', 'post', array( 390 'sort' => true, 391 'args' => array( 392 'orderby' => 'term_order', 393 ), 394 ) ); 395 $term_ids = self::factory()->term->create_many( 2, array( 396 'taxonomy' => 'wptests_tax', 397 ) ); 398 $post_id = self::factory()->post->create(); 399 wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' ); 400 $terms = get_the_terms( $post_id, 'wptests_tax' ); 401 $this->assertEquals( array( $term_ids[0], $term_ids[1] ), wp_list_pluck( $terms, 'term_id' ) ); 402 // Flip the order 403 wp_set_object_terms( $post_id, array( $term_ids[1], $term_ids[0] ), 'wptests_tax' ); 404 $terms = get_the_terms( $post_id, 'wptests_tax' ); 405 $this->assertEquals( array( $term_ids[1], $term_ids[0] ), wp_list_pluck( $terms, 'term_id' ) ); 406 } 407 408 /** 409 * @ticket 40496 410 */ 411 public function test_wp_get_object_terms_should_respect_taxonomy_orderby() { 412 register_taxonomy( 'wptests_tax', 'post', array( 413 'sort' => true, 414 'args' => array( 415 'orderby' => 'term_order', 416 ), 417 ) ); 418 $term_ids = self::factory()->term->create_many( 2, array( 419 'taxonomy' => 'wptests_tax', 420 ) ); 421 $post_id = self::factory()->post->create(); 422 wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' ); 423 $terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) ); 424 $this->assertEquals( array( $term_ids[0], $term_ids[1], 1 ), wp_list_pluck( $terms, 'term_id' ) ); 425 // Flip the order 426 wp_set_object_terms( $post_id, array( $term_ids[1], $term_ids[0] ), 'wptests_tax' ); 427 $terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) ); 428 $this->assertEquals( array( $term_ids[1], $term_ids[0], 1 ), wp_list_pluck( $terms, 'term_id' ) ); 429 } 384 430 }
Note: See TracChangeset
for help on using the changeset viewer.