Ticket #37198: 37198.3.diff
File 37198.3.diff, 23.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-term-query.php
diff --git src/wp-includes/class-wp-term-query.php src/wp-includes/class-wp-term-query.php index 338c940..89e44f2 100644
class WP_Term_Query { 100 100 * 101 101 * @since 4.6.0 102 102 * @since 4.6.0 Introduced 'term_taxonomy_id' parameter. 103 * @since 4.7.0 Introduced 'object_ids' parameter. 103 104 * @access public 104 105 * 105 106 * @param string|array $query { … … class WP_Term_Query { 107 108 * 108 109 * @type string|array $taxonomy Taxonomy name, or array of taxonomies, to which results should 109 110 * be limited. 111 * @type int|array $object_ids Optional. Object ID, or array of object IDs. Results will be 112 * limited to terms associated with these objects. 110 113 * @type string $orderby Field(s) to order terms by. Accepts term fields ('name', 111 114 * 'slug', 'term_group', 'term_id', 'id', 'description'), 112 115 * 'count' for term taxonomy count, 'include' to match the … … class WP_Term_Query { 130 133 * positive number. Default ''|0 (all). 131 134 * @type int $offset The number by which to offset the terms query. Default empty. 132 135 * @type string $fields Term fields to query for. Accepts 'all' (returns an array of 133 * complete term objects), 'ids' (returns an array of ids), 134 * 'id=>parent' (returns an associative array with ids as keys, 135 * parent term IDs as values), 'names' (returns an array of term 136 * names), 'count' (returns the number of matching terms), 137 * 'id=>name' (returns an associative array with ids as keys, 138 * term names as values), or 'id=>slug' (returns an associative 139 * array with ids as keys, term slugs as values). Default 'all'. 136 * complete term objects), 'all_with_object_id' (returns an 137 * array of term objects with the 'object_id' param; only works 138 * when the `$fields` parameter is 'object_ids' ), 'ids' 139 * (returns an array of ids), 'tt_ids' (returns an array of 140 * term taxonomy ids), 'id=>parent' (returns an associative 141 * array with ids as keys, parent term IDs as values), 'names' 142 * (returns an array of term names), 'count' (returns the number 143 * of matching terms), 'id=>name' (returns an associative array 144 * with ids as keys, term names as values), or 'id=>slug' 145 * (returns an associative array with ids as keys, term slugs 146 * as values). Default 'all'. 140 147 * @type bool $count Whether to return a term count (true) or array of term objects 141 148 * (false). Will take precedence over `$fields` if true. 142 149 * Default false. … … class WP_Term_Query { 183 190 184 191 $this->query_var_defaults = array( 185 192 'taxonomy' => null, 193 'object_ids' => null, 186 194 'orderby' => 'name', 187 195 'order' => 'ASC', 188 196 'hide_empty' => true, … … class WP_Term_Query { 397 405 $orderby = "ORDER BY $orderby"; 398 406 } 399 407 400 $order = $this->parse_order( $this->query_vars['order'] ); 408 // 'term_count' is a legal sort order only when joining the relationship table. 409 $_order = $this->query_vars['order']; 410 if ( 'term_count' === $_order && empty( $this->query_vars['object_ids'] ) ) { 411 $_order = 'term_id'; 412 } 413 $order = $this->parse_order( $_order ); 401 414 402 415 if ( $taxonomies ) { 403 416 $this->sql_clauses['where']['taxonomy'] = "tt.taxonomy IN ('" . implode( "', '", array_map( 'esc_sql', $taxonomies ) ) . "')"; … … class WP_Term_Query { 507 520 $this->sql_clauses['where']['description__like'] = $this->db->prepare( "tt.description LIKE %s", '%' . $this->db->esc_like( $args['description__like'] ) . '%' ); 508 521 } 509 522 523 if ( ! empty( $args['object_ids'] ) ) { 524 $object_ids = $args['object_ids']; 525 if ( ! is_array( $object_ids ) ) { 526 $object_ids = array( $object_ids ); 527 } 528 529 $object_ids = implode( ', ', array_map( 'intval', $object_ids ) ); 530 $this->sql_clauses['where']['object_ids'] = "tr.object_id IN ($object_ids)"; 531 } 532 533 /* 534 * When query for object relationships, the 'count > 0' check 535 * added by 'hide_empty' is superfluous. 536 */ 537 if ( ! empty( $args['object_ids'] ) ) { 538 $args['hide_empty'] = false; 539 } 540 510 541 if ( '' !== $parent ) { 511 542 $parent = (int) $parent; 512 543 $this->sql_clauses['where']['parent'] = "tt.parent = '$parent'"; … … class WP_Term_Query { 558 589 $selects = array(); 559 590 switch ( $args['fields'] ) { 560 591 case 'all': 592 case 'all_with_object_id' : 593 case 'tt_ids' : 594 case 'slugs' : 561 595 $selects = array( 't.*', 'tt.*' ); 596 if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) { 597 $selects[] = 'tr.object_id'; 598 } 562 599 break; 563 600 case 'ids': 564 601 case 'id=>parent': … … class WP_Term_Query { 602 639 603 640 $join .= " INNER JOIN {$this->db->term_taxonomy} AS tt ON t.term_id = tt.term_id"; 604 641 642 if ( ! empty( $this->query_vars['object_ids'] ) ) { 643 $join .= " INNER JOIN {$this->db->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id"; 644 } 645 605 646 $where = implode( ' AND ', $this->sql_clauses['where'] ); 606 647 607 648 /** … … class WP_Term_Query { 657 698 } 658 699 659 700 $terms = $this->db->get_results( $this->request ); 660 if ( 'all' == $_fields ) {701 if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) { 661 702 update_term_cache( $terms ); 662 703 } 663 704 … … class WP_Term_Query { 708 749 } 709 750 } 710 751 752 /* 753 * When querying for terms connected to objects, we may get 754 * duplicate results. The duplicates should be preserved if 755 * `$fields` is 'all_with_object_id', but should otherwise be 756 * removed. 757 */ 758 if ( ! empty( $args['object_ids'] ) && 'all_with_object_id' != $_fields ) { 759 $_tt_ids = $_terms = array(); 760 foreach ( $terms as $term ) { 761 if ( isset( $_tt_ids[ $term->term_id ] ) ) { 762 continue; 763 } 764 765 $_tt_ids[ $term->term_id ] = 1; 766 $_terms[] = $term; 767 } 768 769 $terms = $_terms; 770 } 771 711 772 $_terms = array(); 712 773 if ( 'id=>parent' == $_fields ) { 713 774 foreach ( $terms as $term ) { … … class WP_Term_Query { 715 776 } 716 777 } elseif ( 'ids' == $_fields ) { 717 778 foreach ( $terms as $term ) { 718 $_terms[] = $term->term_id; 779 $_terms[] = (int) $term->term_id; 780 } 781 } elseif ( 'tt_ids' == $_fields ) { 782 foreach ( $terms as $term ) { 783 $_terms[] = (int) $term->term_taxonomy_id; 719 784 } 720 785 } elseif ( 'names' == $_fields ) { 721 786 foreach ( $terms as $term ) { 722 787 $_terms[] = $term->name; 723 788 } 789 } elseif ( 'slugs' == $_fields ) { 790 foreach ( $terms as $term ) { 791 $_terms[] = $term->slug; 792 } 724 793 } elseif ( 'id=>name' == $_fields ) { 725 794 foreach ( $terms as $term ) { 726 795 $_terms[ $term->term_id ] = $term->name; … … class WP_Term_Query { 746 815 747 816 wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); 748 817 749 if ( 'all' === $_fields ) {818 if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) { 750 819 $terms = array_map( 'get_term', $terms ); 751 820 } 752 821 … … class WP_Term_Query { 766 835 protected function parse_orderby( $orderby_raw ) { 767 836 $_orderby = strtolower( $orderby_raw ); 768 837 $maybe_orderby_meta = false; 769 if ( 'count' == $_orderby ) { 770 $orderby = 'tt.count'; 771 } elseif ( 'name' == $_orderby ) { 772 $orderby = 't.name'; 773 } elseif ( 'slug' == $_orderby ) { 774 $orderby = 't.slug'; 838 839 if ( in_array( $_orderby, array( 'term_id', 'name', 'slug', 'term_group' ), true ) ) { 840 $orderby = "t.$_orderby"; 841 } elseif ( in_array( $_orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id', 'description' ), true ) ) { 842 $orderby = "tt.$_orderby"; 843 } elseif ( 'term_order' === $_orderby ) { 844 $orderby = 'tr.term_order'; 775 845 } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) { 776 846 $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) ); 777 847 $orderby = "FIELD( t.term_id, $include )"; 778 } elseif ( 'term_group' == $_orderby ) {779 $orderby = 't.term_group';780 } elseif ( 'description' == $_orderby ) {781 $orderby = 'tt.description';782 848 } elseif ( 'none' == $_orderby ) { 783 849 $orderby = ''; 784 850 } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) { -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index 80e1f84..d1d5510 100644
function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { 1983 1983 $object_ids = array($object_ids); 1984 1984 $object_ids = array_map('intval', $object_ids); 1985 1985 1986 $defaults = array( 1987 'orderby' => 'name', 1988 'order' => 'ASC', 1989 'fields' => 'all', 1990 'parent' => '', 1991 'update_term_meta_cache' => true, 1992 'meta_query' => '', 1993 ); 1994 $args = wp_parse_args( $args, $defaults ); 1995 1996 $terms = array(); 1997 if ( count($taxonomies) > 1 ) { 1998 foreach ( $taxonomies as $index => $taxonomy ) { 1999 $t = get_taxonomy($taxonomy); 2000 if ( isset($t->args) && is_array($t->args) && $args != array_merge($args, $t->args) ) { 2001 unset($taxonomies[$index]); 2002 $terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args))); 2003 } 2004 } 2005 } else { 2006 $t = get_taxonomy($taxonomies[0]); 2007 if ( isset($t->args) && is_array($t->args) ) 2008 $args = array_merge($args, $t->args); 2009 } 2010 2011 $orderby = $args['orderby']; 2012 $order = $args['order']; 2013 $fields = $args['fields']; 2014 2015 if ( in_array( $orderby, array( 'term_id', 'name', 'slug', 'term_group' ) ) ) { 2016 $orderby = "t.$orderby"; 2017 } elseif ( in_array( $orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id' ) ) ) { 2018 $orderby = "tt.$orderby"; 2019 } elseif ( 'term_order' === $orderby ) { 2020 $orderby = 'tr.term_order'; 2021 } elseif ( 'none' === $orderby ) { 2022 $orderby = ''; 2023 $order = ''; 2024 } else { 2025 $orderby = 't.term_id'; 2026 } 2027 2028 // tt_ids queries can only be none or tr.term_taxonomy_id 2029 if ( ('tt_ids' == $fields) && !empty($orderby) ) 2030 $orderby = 'tr.term_taxonomy_id'; 2031 2032 if ( !empty($orderby) ) 2033 $orderby = "ORDER BY $orderby"; 2034 2035 $order = strtoupper( $order ); 2036 if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) 2037 $order = 'ASC'; 2038 2039 $taxonomy_array = $taxonomies; 2040 $object_id_array = $object_ids; 2041 $taxonomies = "'" . implode("', '", array_map( 'esc_sql', $taxonomies ) ) . "'"; 2042 $object_ids = implode(', ', $object_ids); 2043 2044 $select_this = ''; 2045 if ( 'all' == $fields ) { 2046 $select_this = 't.*, tt.*'; 2047 } elseif ( 'ids' == $fields ) { 2048 $select_this = 't.term_id'; 2049 } elseif ( 'names' == $fields ) { 2050 $select_this = 't.name'; 2051 } elseif ( 'slugs' == $fields ) { 2052 $select_this = 't.slug'; 2053 } elseif ( 'all_with_object_id' == $fields ) { 2054 $select_this = 't.*, tt.*, tr.object_id'; 2055 } 2056 2057 $where = array( 2058 "tt.taxonomy IN ($taxonomies)", 2059 "tr.object_id IN ($object_ids)", 2060 ); 2061 2062 if ( '' !== $args['parent'] ) { 2063 $where[] = $wpdb->prepare( 'tt.parent = %d', $args['parent'] ); 2064 } 2065 2066 // Meta query support. 2067 $meta_query_join = ''; 2068 if ( ! empty( $args['meta_query'] ) ) { 2069 $mquery = new WP_Meta_Query( $args['meta_query'] ); 2070 $mq_sql = $mquery->get_sql( 'term', 't', 'term_id' ); 2071 2072 $meta_query_join .= $mq_sql['join']; 2073 2074 // Strip leading AND. 2075 $where[] = preg_replace( '/^\s*AND/', '', $mq_sql['where'] ); 2076 } 2077 2078 $where = implode( ' AND ', $where ); 2079 2080 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id $meta_query_join WHERE $where $orderby $order"; 1986 $args['taxonomy'] = $taxonomies; 1987 $args['object_ids'] = $object_ids; 2081 1988 2082 $objects = false; 2083 if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 2084 $_terms = $wpdb->get_results( $query ); 2085 $object_id_index = array(); 2086 foreach ( $_terms as $key => $term ) { 2087 $term = sanitize_term( $term, $taxonomy, 'raw' ); 2088 $_terms[ $key ] = $term; 2089 2090 if ( isset( $term->object_id ) ) { 2091 $object_id_index[ $key ] = $term->object_id; 2092 } 2093 } 2094 2095 update_term_cache( $_terms ); 2096 $_terms = array_map( 'get_term', $_terms ); 2097 2098 // Re-add the object_id data, which is lost when fetching terms from cache. 2099 if ( 'all_with_object_id' === $fields ) { 2100 foreach ( $_terms as $key => $_term ) { 2101 if ( isset( $object_id_index[ $key ] ) ) { 2102 $_term->object_id = $object_id_index[ $key ]; 2103 } 2104 } 2105 } 2106 2107 $terms = array_merge( $terms, $_terms ); 2108 $objects = true; 2109 2110 } elseif ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) { 2111 $_terms = $wpdb->get_col( $query ); 2112 $_field = ( 'ids' == $fields ) ? 'term_id' : 'name'; 2113 foreach ( $_terms as $key => $term ) { 2114 $_terms[$key] = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw' ); 2115 } 2116 $terms = array_merge( $terms, $_terms ); 2117 } elseif ( 'tt_ids' == $fields ) { 2118 $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order"); 2119 foreach ( $terms as $key => $tt_id ) { 2120 $terms[$key] = sanitize_term_field( 'term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw' ); // 0 should be the term id, however is not needed when using raw context. 2121 } 2122 } 2123 2124 // Update termmeta cache, if necessary. 2125 if ( $args['update_term_meta_cache'] && ( 'all' === $fields || 'all_with_object_id' === $fields || 'ids' === $fields ) ) { 2126 if ( 'ids' === $fields ) { 2127 $term_ids = $terms; 2128 } else { 2129 $term_ids = wp_list_pluck( $terms, 'term_id' ); 2130 } 2131 2132 update_termmeta_cache( $term_ids ); 2133 } 2134 2135 if ( ! $terms ) { 2136 $terms = array(); 2137 } elseif ( $objects && 'all_with_object_id' !== $fields ) { 2138 $_tt_ids = array(); 2139 $_terms = array(); 2140 foreach ( $terms as $term ) { 2141 if ( in_array( $term->term_taxonomy_id, $_tt_ids ) ) { 2142 continue; 2143 } 2144 2145 $_tt_ids[] = $term->term_taxonomy_id; 2146 $_terms[] = $term; 2147 } 2148 $terms = $_terms; 2149 } elseif ( ! $objects ) { 2150 $terms = array_values( array_unique( $terms ) ); 2151 } 1989 $terms = get_terms( $args ); 2152 1990 2153 1991 /** 2154 1992 * Filters the terms for a given object or objects. 2155 1993 * 2156 1994 * @since 4.2.0 2157 1995 * 2158 * @param array $terms 2159 * @param array $object_id _arrayArray of object IDs for which `$terms` were retrieved.2160 * @param array $taxonom y_arrayArray of taxonomies from which `$terms` were retrieved.2161 * @param array $args 2162 * 1996 * @param array $terms An array of terms for the given object or objects. 1997 * @param array $object_ids Array of object IDs for which `$terms` were retrieved. 1998 * @param array $taxonomies Array of taxonomies from which `$terms` were retrieved. 1999 * @param array $args An array of arguments for retrieving terms for the given 2000 * object(s). See wp_get_object_terms() for details. 2163 2001 */ 2164 $terms = apply_filters( 'get_object_terms', $terms, $object_id_array, $taxonomy_array, $args ); 2002 $terms = apply_filters( 'get_object_terms', $terms, $object_ids, $taxonomies, $args ); 2003 2004 $object_ids = implode( ',', $object_ids ); 2005 $taxonomies = implode( ',', $taxonomies ); 2165 2006 2166 2007 /** 2167 2008 * Filters the terms for a given object or objects. -
tests/phpunit/tests/term/query.php
diff --git tests/phpunit/tests/term/query.php tests/phpunit/tests/term/query.php index a70bfd5..09f4ee4 100644
class Tests_Term_Query extends WP_UnitTestCase { 185 185 186 186 $this->assertEquals( array( $t1, $t2 ), $terms ); 187 187 } 188 189 /** 190 * @ticket 37198 191 */ 192 public function test_object_ids_single() { 193 register_taxonomy( 'wptests_tax_1', 'post' ); 194 195 $p = self::factory()->post->create(); 196 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 197 198 wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' ); 199 200 $query = new WP_Term_Query( array( 201 'taxonomy' => 'wptests_tax_1', 202 'object_ids' => $p, 203 'fields' => 'ids', 204 ) ); 205 206 $this->assertEqualSets( array( $t ), $query->terms ); 207 } 208 209 /** 210 * @ticket 37198 211 */ 212 public function test_object_ids_array() { 213 register_taxonomy( 'wptests_tax_1', 'post' ); 214 215 $p = self::factory()->post->create(); 216 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 217 218 wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' ); 219 220 $query = new WP_Term_Query( array( 221 'taxonomy' => 'wptests_tax_1', 222 'object_ids' => array( $p ), 223 'fields' => 'ids', 224 ) ); 225 226 $this->assertEqualSets( array( $t ), $query->terms ); 227 } 228 229 /** 230 * @ticket 37198 231 */ 232 public function test_duplicates_should_be_removed_for_fields_all() { 233 register_taxonomy( 'wptests_tax_1', 'post' ); 234 $posts = self::factory()->post->create_many( 2 ); 235 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 236 237 foreach ( $posts as $p ) { 238 wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' ); 239 } 240 241 $query = new WP_Term_Query( array( 242 'taxonomy' => 'wptests_tax_1', 243 'object_ids' => $posts, 244 'fields' => 'all', 245 ) ); 246 247 $this->assertSame( 1, count( $query->terms ) ); 248 $this->assertSame( $t, reset( $query->terms )->term_id ); 249 } 250 251 /** 252 * @ticket 37198 253 */ 254 public function test_duplicates_should_not_be_removed_for_fields_all_with_object_id() { 255 register_taxonomy( 'wptests_tax_1', 'post' ); 256 $posts = self::factory()->post->create_many( 2 ); 257 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 258 259 foreach ( $posts as $p ) { 260 wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' ); 261 } 262 263 $query = new WP_Term_Query( array( 264 'taxonomy' => 'wptests_tax_1', 265 'object_ids' => $posts, 266 'fields' => 'all_with_object_id', 267 ) ); 268 269 $this->assertSame( 2, count( $query->terms ) ); 270 foreach ( $query->terms as $term ) { 271 $this->assertSame( $t, $term->term_id ); 272 } 273 } 274 275 /** 276 * @ticket 37198 277 * @group cache 278 */ 279 public function test_object_ids_cache_should_be_invalidated_by_term_relationship_change() { 280 register_taxonomy( 'wptests_tax_1', 'post' ); 281 282 $p = self::factory()->post->create(); 283 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) ); 284 285 wp_set_object_terms( $p, array( $terms[0] ), 'wptests_tax_1' ); 286 287 $query = new WP_Term_Query( array( 288 'taxonomy' => 'wptests_tax_1', 289 'object_ids' => $p, 290 'fields' => 'ids', 291 ) ); 292 $found = $query->get_terms(); 293 294 $this->assertEqualSets( array( $terms[0] ), $found ); 295 296 wp_set_object_terms( $p, array( $terms[1] ), 'wptests_tax_1' ); 297 298 $query = new WP_Term_Query( array( 299 'taxonomy' => 'wptests_tax_1', 300 'object_ids' => $p, 301 'fields' => 'ids', 302 ) ); 303 $found = $query->get_terms(); 304 305 $this->assertEqualSets( array( $terms[1] ), $found ); 306 } 188 307 } -
tests/phpunit/tests/term/wpGetObjectTerms.php
diff --git tests/phpunit/tests/term/wpGetObjectTerms.php tests/phpunit/tests/term/wpGetObjectTerms.php index 892e7a1..a035501 100644
class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { 23 23 $this->assertEquals( 3, count($tt_1) ); 24 24 25 25 // make sure they're correct 26 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'slugs', 'orderby' => 't .term_id'));26 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'slugs', 'orderby' => 'term_id')); 27 27 $this->assertEquals( $terms_1_slugs, $terms ); 28 28 } 29 29 … … class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { 360 360 * @ticket 15675 361 361 */ 362 362 public function test_parent() { 363 register_taxonomy( 'wptests_tax2', 'post', array( 364 'hierarchical' => true, 365 ) ); 366 363 367 $t1 = self::factory()->term->create( array( 364 'taxonomy' => $this->taxonomy,368 'taxonomy' => 'wptests_tax2', 365 369 ) ); 366 370 $t2 = self::factory()->term->create( array( 367 'taxonomy' => $this->taxonomy,371 'taxonomy' => 'wptests_tax2', 368 372 ) ); 369 373 $t3 = self::factory()->term->create( array( 370 'taxonomy' => $this->taxonomy,374 'taxonomy' => 'wptests_tax2', 371 375 'parent' => $t1, 372 376 ) ); 373 377 $t4 = self::factory()->term->create( array( 374 'taxonomy' => $this->taxonomy,378 'taxonomy' => 'wptests_tax2', 375 379 'parent' => $t2, 376 380 ) ); 377 381 378 382 $p = self::factory()->post->create(); 379 383 380 wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), $this->taxonomy);384 wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), 'wptests_tax2' ); 381 385 382 $found = wp_get_object_terms( $p, $this->taxonomy, array(386 $found = wp_get_object_terms( $p, 'wptests_tax2', array( 383 387 'parent' => $t1, 384 388 'fields' => 'ids', 385 389 ) ); -
tests/phpunit/tests/term/wpSetObjectTerms.php
diff --git tests/phpunit/tests/term/wpSetObjectTerms.php tests/phpunit/tests/term/wpSetObjectTerms.php index 279f448..6f126b3 100644
class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { 259 259 $this->assertEquals( 3, count($tt_1) ); 260 260 261 261 // make sure they're correct 262 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't .term_id'));262 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 'term_id')); 263 263 $this->assertEquals( $terms_1, $terms ); 264 264 265 265 // change the terms … … class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { 267 267 $this->assertEquals( 2, count($tt_2) ); 268 268 269 269 // make sure they're correct 270 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't .term_id'));270 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 'term_id')); 271 271 $this->assertEquals( $terms_2, $terms ); 272 272 273 273 // make sure the tt id for 'bar' matches … … class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { 288 288 $this->assertEquals( 3, count($tt_1) ); 289 289 290 290 // make sure they're correct 291 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't .term_id'));291 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 'term_id')); 292 292 $this->assertEquals( $terms_1, $terms ); 293 293 294 294 // change the terms … … class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { 296 296 $this->assertEquals( 2, count($tt_2) ); 297 297 298 298 // make sure they're correct 299 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't .term_id'));299 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 'term_id')); 300 300 $this->assertEquals( $terms_2, $terms ); 301 301 302 302 // make sure the tt id for 'bar' matches