Make WordPress Core

Changeset 27647


Ignore:
Timestamp:
03/21/2014 05:20:52 PM (13 years ago)
Author:
nacin
Message:

In WP_Query::get_queried_object(), account for pre_get_posts by checking for tag when tag_id isn't present.

Merges [27511] to the 3.8 branch.

props mattonomics, wonderboymusic.
fixes #27362.

Location:
branches/3.8
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8

  • branches/3.8/src/wp-includes/query.php

    r26951 r27647  
    32743274                                }
    32753275                        } elseif ( $this->is_tag ) {
    3276                                 $term = get_term( $this->get( 'tag_id' ), 'post_tag' );
     3276                                if ( $this->get( 'tag_id' ) ) {
     3277                                        $term = get_term( $this->get( 'tag_id' ), 'post_tag' );
     3278                                } elseif ( $this->get( 'tag' ) ) {
     3279                                        $term = get_term_by( 'slug', $this->get( 'tag' ), 'post_tag' );
     3280                                }
    32773281                        } else {
    32783282                                $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
  • branches/3.8/tests/phpunit/tests/query.php

    r25601 r27647  
    7979
    8080        }
     81
     82        /**
     83         * @ticket 26627
     84         */
     85        function test_tag_queried_object() {
     86                $slug = 'tag-slug-26627';
     87                $this->factory->tag->create( array( 'slug' => $slug ) );
     88                $tag = get_term_by( 'slug', $slug, 'post_tag' );
     89
     90                add_action( 'pre_get_posts', array( $this, '_tag_queried_object' ), 11 );
     91
     92                $this->go_to( get_term_link( $tag ) );
     93
     94                $this->assertQueryTrue( 'is_tag', 'is_archive' );
     95                $this->assertNotEmpty( get_query_var( 'tag_id' ) );
     96                $this->assertNotEmpty( get_query_var( 'tag' ) );
     97                $this->assertEmpty( get_query_var( 'tax_query' ) );
     98                $this->assertCount( 1, get_query_var( 'tag_slug__in' ) );
     99                $this->assertEquals( get_queried_object(), $tag );
     100
     101                remove_action( 'pre_get_posts', array( $this, '_tag_queried_object' ), 11 );
     102        }
     103
     104        function _tag_queried_object( &$query ) {
     105                $tag = get_term_by( 'slug', 'tag-slug-26627', 'post_tag' );
     106                $this->assertTrue( $query->is_tag() );
     107                $this->assertTrue( $query->is_archive() );
     108                $this->assertNotEmpty( $query->get( 'tag' ) );
     109                $this->assertCount( 1, $query->get( 'tag_slug__in' ) );
     110                $this->assertEquals( $query->get_queried_object(), $tag );
     111        }
    81112}
Note: See TracChangeset for help on using the changeset viewer.