Changeset 31366
- Timestamp:
- 02/07/2015 07:49:17 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r31340 r31366 3901 3901 $tax_query_in_and = wp_list_filter( $this->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' ); 3902 3902 3903 $queried_taxonomies = array_keys( $tax_query_in_and ); 3904 $matched_taxonomy = reset( $queried_taxonomies ); 3905 $query = $tax_query_in_and[ $matched_taxonomy ]; 3906 3907 if ( $query['terms'] ) { 3908 if ( 'term_id' == $query['field'] ) { 3909 $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); 3910 } else { 3911 $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); 3903 if ( ! empty( $tax_query_in_and ) ) { 3904 $queried_taxonomies = array_keys( $tax_query_in_and ); 3905 $matched_taxonomy = reset( $queried_taxonomies ); 3906 $query = $tax_query_in_and[ $matched_taxonomy ]; 3907 3908 if ( $query['terms'] ) { 3909 if ( 'term_id' == $query['field'] ) { 3910 $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); 3911 } else { 3912 $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); 3913 } 3912 3914 } 3913 3915 } -
trunk/tests/phpunit/tests/query.php
r30085 r31366 92 92 $this->assertEquals( $query->get_queried_object(), $tag ); 93 93 } 94 95 /** 96 * @ticket 31246 97 */ 98 public function test_get_queried_object_should_return_null_when_is_tax_is_true_but_the_taxonomy_args_have_been_removed_in_a_parse_query_callback() { 99 // Don't override the args provided below. 100 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); 101 register_taxonomy( 'wptests_tax', 'post' ); 102 $terms = $this->factory->term->create_many( 2, array( 103 'taxonomy' => 'wptests_tax', 104 ) ); 105 106 $posts = $this->factory->post->create_many( 2 ); 107 108 wp_set_object_terms( $posts[0], array( $terms[0] ), 'wptests_tax' ); 109 wp_set_object_terms( $posts[1], array( $terms[1] ), 'wptests_tax' ); 110 111 add_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) ); 112 $q = new WP_Query( array( 113 'fields' => 'ids', 114 'wptests_tax' => $terms[1], 115 ) ); 116 117 remove_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) ); 118 119 $this->assertNull( $q->get_queried_object() ); 120 } 121 122 public function filter_parse_query_to_remove_tax( $q ) { 123 unset( $q->query_vars['wptests_tax'] ); 124 } 94 125 }
Note: See TracChangeset
for help on using the changeset viewer.