Ticket #41293: 41293.4.patch
File 41293.4.patch, 3.3 KB (added by , 7 years ago) |
---|
-
src/wp-includes/taxonomy.php
1857 1857 * @return array|WP_Error The requested term data or empty array if no terms found. 1858 1858 * WP_Error if any of the $taxonomies don't exist. 1859 1859 */ 1860 function wp_get_object_terms( $object_ids, $taxonomies, $args = array()) {1860 function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { 1861 1861 if ( empty( $object_ids ) || empty( $taxonomies ) ) 1862 1862 return array(); 1863 1863 1864 if ( ! is_array($taxonomies) )1865 $taxonomies = array( $taxonomies);1864 if ( ! is_array( $taxonomies ) ) 1865 $taxonomies = array( $taxonomies ); 1866 1866 1867 1867 foreach ( $taxonomies as $taxonomy ) { 1868 if ( ! taxonomy_exists( $taxonomy) )1868 if ( ! taxonomy_exists( $taxonomy ) ) 1869 1869 return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); 1870 1870 } 1871 1871 1872 if ( ! is_array($object_ids) )1873 $object_ids = array( $object_ids);1874 $object_ids = array_map( 'intval', $object_ids);1872 if ( ! is_array( $object_ids ) ) 1873 $object_ids = array( $object_ids ); 1874 $object_ids = array_map( 'intval', $object_ids ); 1875 1875 1876 1876 $args = wp_parse_args( $args ); 1877 1877 … … 1912 1912 1913 1913 // Taxonomies registered without an 'args' param are handled here. 1914 1914 if ( ! empty( $taxonomies ) ) { 1915 $terms = array_merge( $terms, get_terms( $args ) ); 1915 $terms_from_remaining_taxonomies = get_terms( $args ); 1916 1917 // Array keys should be preserved for values of $fields that use term_id for keys. 1918 if ( ! empty( $args['fields'] ) && 0 === strpos( $args['fields'], 'id=>' ) ) { 1919 $terms = $terms + $terms_from_remaining_taxonomies; 1920 } else { 1921 $terms = array_merge( $terms, $terms_from_remaining_taxonomies ); 1922 } 1916 1923 } 1917 1924 1918 1925 /** -
tests/phpunit/tests/term/query.php
429 429 } 430 430 431 431 /** 432 * @ticket 41293 433 */ 434 public function test_should_allow_same_args_with_the_get_terms() { 435 register_post_type( 'wptests_pt' ); 436 register_taxonomy( 'wptests_tax', 'wptests_pt' ); 437 $t1 = self::factory()->term->create( array( 438 'taxonomy' => 'wptests_tax', 439 'name' => 'foo', 440 'slug' => 'bar', 441 ) ); 442 $t2 = self::factory()->term->create( array( 443 'taxonomy' => 'wptests_tax', 444 'name' => 'bar', 445 'slug' => 'foo', 446 ) ); 447 448 $p = self::factory()->post->create( array( 449 'post_type' => 'wptests_pt', 450 ) ); 451 452 wp_set_object_terms( $p, array( $t1, $t2 ), 'wptests_tax' ); 453 454 $expected = wp_get_post_terms( $p, 'wptests_tax', array( 455 'fields' => 'ids', 456 ) ); 457 458 $found1 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array( 459 'fields' => 'id=>parent', 460 ) ) ); 461 462 $found2 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array( 463 'fields' => 'id=>slug', 464 ) ) ); 465 466 $found3 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array( 467 'fields' => 'id=>name', 468 ) ) ); 469 470 $this->assertSame( $expected, $found1 ); 471 $this->assertSame( $expected, $found2 ); 472 $this->assertSame( $expected, $found3 ); 473 } 474 475 /** 432 476 * @ticket 41796 433 477 */ 434 478 public function test_number_should_work_with_object_ids() {