Changeset 30771
- Timestamp:
- 12/07/2014 02:57:53 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r30682 r30771 3870 3870 } 3871 3871 } else { 3872 $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); 3873 $query = reset( $tax_query_in_and ); 3872 // For other tax queries, grab the first term from the first clause. 3873 $tax_query_in_and = wp_list_filter( $this->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' ); 3874 3875 $queried_taxonomies = array_keys( $tax_query_in_and ); 3876 $matched_taxonomy = reset( $queried_taxonomies ); 3877 $query = $tax_query_in_and[ $matched_taxonomy ]; 3874 3878 3875 3879 if ( $query['terms'] ) { 3876 3880 if ( 'term_id' == $query['field'] ) { 3877 $term = get_term( reset( $query['terms'] ), $ query['taxonomy']);3881 $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); 3878 3882 } else { 3879 $term = get_term_by( $query['field'], reset( $query['terms'] ), $ query['taxonomy']);3883 $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); 3880 3884 } 3881 3885 } -
trunk/tests/phpunit/tests/query/taxQuery.php
r28966 r30771 181 181 ) ); 182 182 } 183 184 /** 185 * @group 30623 186 */ 187 public function test_get_queried_object_with_custom_taxonomy_tax_query_and_field_term_id_should_return_term_object() { 188 // Don't override the args provided below. 189 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); 190 191 $args = array( 192 'tax_query' => array( 193 'relation' => 'AND', 194 array( 195 'taxonomy' => 'testtax', 196 'field' => 'term_id', 197 'terms' => array( 198 $this->tax_id, 199 ), 200 ), 201 ) 202 ); 203 204 $q = new WP_Query( $args ); 205 $object = $q->get_queried_object(); 206 207 $expected = get_term( $this->tax_id, 'testtax' ); 208 209 $this->assertEquals( $expected, $object ); 210 } 211 212 /** 213 * @group 30623 214 */ 215 public function test_get_queried_object_with_custom_taxonomy_tax_query_and_field_slug_should_return_term_object() { 216 // Don't override the args provided below. 217 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); 218 219 $args = array( 220 'tax_query' => array( 221 'relation' => 'AND', 222 array( 223 'taxonomy' => 'testtax', 224 'field' => 'slug', 225 'terms' => array( 226 'tax-slug', 227 ), 228 ), 229 ) 230 ); 231 232 $q = new WP_Query( $args ); 233 $object = $q->get_queried_object(); 234 235 $expected = get_term( $this->tax_id, 'testtax' ); 236 237 // Only compare term_id because object_id may or may not be part of either value. 238 $this->assertEquals( $expected->term_id, $object->term_id ); 239 } 240 241 /** 242 * @group 30623 243 */ 244 public function test_get_queried_object_with_custom_taxonomy_tax_query_with_multiple_clauses_should_return_term_object_corresponding_to_the_first_queried_tax() { 245 // Don't override the args provided below. 246 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); 247 248 register_taxonomy( 'testtax2', 'post' ); 249 $testtax2_term_id = $this->factory->term->create( array( 250 'taxonomy' => 'testtax2', 251 'slug' => 'testtax2-slug', 252 ) ); 253 254 $args = array( 255 'tax_query' => array( 256 'relation' => 'AND', 257 array( 258 'taxonomy' => 'testtax', 259 'field' => 'slug', 260 'terms' => array( 261 'tax-slug', 262 ), 263 ), 264 array( 265 'taxonomy' => 'testtax2', 266 'field' => 'slug', 267 'terms' => array( 268 'testtax2-slug', 269 ), 270 ), 271 ) 272 ); 273 274 $q = new WP_Query( $args ); 275 $object = $q->get_queried_object(); 276 277 $expected = get_term( $this->tax_id, 'testtax' ); 278 279 // Only compare term_id because object_id may or may not be part of either value. 280 $this->assertEquals( $expected->term_id, $object->term_id ); 281 } 183 282 }
Note: See TracChangeset
for help on using the changeset viewer.