Ticket #20767: 20767.2.diff
File 20767.2.diff, 3.6 KB (added by , 10 years ago) |
---|
-
src/wp-includes/query.php
3057 3057 $this->queried_object_id = 0; 3058 3058 3059 3059 if ( $this->is_category || $this->is_tag || $this->is_tax ) { 3060 $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); 3060 if ( $this->is_tag ) { 3061 $term = get_term( $this->get( 'tag_id' ), 'post_tag' ); 3062 } else if ( $this->is_category ) { 3063 $term = get_term( $this->get( 'cat' ), 'category' ); 3064 } else { 3065 $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); 3066 $query = reset( $tax_query_in_and ); 3061 3067 3062 $query = reset( $tax_query_in_and ); 3068 if ( 'term_id' == $query['field'] ) 3069 $term = get_term( reset( $query['terms'] ), $query['taxonomy'] ); 3070 else 3071 $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] ); 3072 } 3063 3073 3064 if ( 'term_id' == $query['field'] )3065 $term = get_term( reset( $query['terms'] ), $query['taxonomy'] );3066 elseif ( $query['terms'] )3067 $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );3068 3069 3074 if ( ! empty( $term ) && ! is_wp_error( $term ) ) { 3070 3075 $this->queried_object = $term; 3071 3076 $this->queried_object_id = (int) $term->term_id; 3072 3077 3073 if ( $this->is_category )3078 if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) 3074 3079 _make_cat_compat( $this->queried_object ); 3075 3080 } 3076 3081 } elseif ( $this->is_post_type_archive ) { -
tests/phpunit/tests/query/conditionals.php
716 716 function pre_get_posts_with_type_array( &$query ) { 717 717 $query->set( 'post_type', array( 'post', 'thearray' ) ); 718 718 } 719 720 function test_tax_category_tax_query() { 721 register_taxonomy( 'testtax', array( 'public' => true ) ); 722 723 $tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) ); 724 $cat_id = $this->factory->category->create( array( 'slug' => 'cat-slug' ) ); 725 $tax_id = $this->factory->term->create( array( 'taxonomy' => 'testtax', 'slug' => 'tax-slug' ) ); 726 $post_id = $this->factory->post->create(); 727 wp_set_object_terms( $post_id, $tag_id, 'post_tag' ); 728 wp_set_object_terms( $post_id, $cat_id, 'category' ); 729 wp_set_object_terms( $post_id, $tax_id, 'testtax' ); 730 731 add_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); 732 733 $this->go_to( "/tag/tag-slug/" ); 734 $this->assertQueryTrue( 'is_tag', 'is_archive' ); 735 $this->assertEquals( get_queried_object(), get_term( $tag_id, 'post_tag' ) ); 736 737 $this->go_to( "/category/cat-slug/" ); 738 $this->assertQueryTrue( 'is_category', 'is_archive' ); 739 $cat = get_term( $cat_id, 'category' ); 740 _make_cat_compat( $cat ); 741 $this->assertEquals( get_queried_object(), $cat ); 742 743 $this->go_to( "/tag/tag-slug/?cat=$cat_id" ); 744 $this->assertQueryTrue( 'is_tag', 'is_category', 'is_archive' ); 745 $this->assertEquals( get_queried_object(), get_term( $tag_id, 'post_tag' ) ); 746 747 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); 748 } 749 750 function pre_get_posts_tax_category_tax_query( &$query ) { 751 $term = get_term_by( 'slug', 'tax-slug', 'testtax' ); 752 $query->set( 'tax_query', array( 753 array( 'taxonomy' => 'testtax', 'field' => 'term_id', 'terms' => $term->term_id ) 754 ) ); 755 } 719 756 }