Changeset 52822
- Timestamp:
- 03/05/2022 03:33:05 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r52332 r52822 3564 3564 if ( $this->is_category || $this->is_tag || $this->is_tax ) { 3565 3565 if ( $this->is_category ) { 3566 if ( $this->get( 'cat' ) ) { 3567 $term = get_term( $this->get( 'cat' ), 'category' ); 3568 } elseif ( $this->get( 'category_name' ) ) { 3569 $term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' ); 3566 $cat = $this->get( 'cat' ); 3567 $category_name = $this->get( 'category_name' ); 3568 3569 if ( $cat ) { 3570 $term = get_term( $cat, 'category' ); 3571 } elseif ( $category_name ) { 3572 $term = get_term_by( 'slug', $category_name, 'category' ); 3570 3573 } 3571 3574 } elseif ( $this->is_tag ) { 3572 if ( $this->get( 'tag_id' ) ) { 3573 $term = get_term( $this->get( 'tag_id' ), 'post_tag' ); 3574 } elseif ( $this->get( 'tag' ) ) { 3575 $term = get_term_by( 'slug', $this->get( 'tag' ), 'post_tag' ); 3575 $tag_id = $this->get( 'tag_id' ); 3576 $tag = $this->get( 'tag' ); 3577 3578 if ( $tag_id ) { 3579 $term = get_term( $tag_id, 'post_tag' ); 3580 } elseif ( $tag ) { 3581 $term = get_term_by( 'slug', $tag, 'post_tag' ); 3576 3582 } 3577 3583 } else { … … 3602 3608 } elseif ( $this->is_post_type_archive ) { 3603 3609 $post_type = $this->get( 'post_type' ); 3610 3604 3611 if ( is_array( $post_type ) ) { 3605 3612 $post_type = reset( $post_type ); 3606 3613 } 3614 3607 3615 $this->queried_object = get_post_type_object( $post_type ); 3608 3616 } elseif ( $this->is_posts_page ) { 3609 $page_for_posts = get_option( 'page_for_posts' ); 3617 $page_for_posts = get_option( 'page_for_posts' ); 3618 3610 3619 $this->queried_object = get_post( $page_for_posts ); 3611 3620 $this->queried_object_id = (int) $this->queried_object->ID; … … 3614 3623 $this->queried_object_id = (int) $this->post->ID; 3615 3624 } elseif ( $this->is_author ) { 3616 $this->queried_object_id = (int) $this->get( 'author' ); 3617 $this->queried_object = get_userdata( $this->queried_object_id ); 3625 $author = (int) $this->get( 'author' ); 3626 $author_name = $this->get( 'author_name' ); 3627 3628 if ( $author ) { 3629 $this->queried_object_id = $author; 3630 } elseif ( $author_name ) { 3631 $user = get_user_by( 'slug', $author_name ); 3632 3633 if ( $user ) { 3634 $this->queried_object_id = $user->ID; 3635 } 3636 } 3637 3638 $this->queried_object = get_userdata( $this->queried_object_id ); 3618 3639 } 3619 3640 -
trunk/tests/phpunit/tests/query.php
r52010 r52822 697 697 $this->assertSame( 'term1', get_query_var( 'term' ) ); 698 698 } 699 700 /** 701 * @ticket 55100 702 */ 703 public function test_get_queried_object_should_work_for_author_name_before_get_posts() { 704 $user_id = self::factory()->user->create(); 705 $user = get_user_by( 'ID', $user_id ); 706 $post_id = self::factory()->post->create( 707 array( 708 'post_author' => $user_id, 709 ) 710 ); 711 712 $this->go_to( home_url( '?author=' . $user_id ) ); 713 714 $this->assertInstanceOf( 'WP_User', get_queried_object() ); 715 $this->assertSame( get_queried_object_id(), $user_id ); 716 717 $this->go_to( home_url( '?author_name=' . $user->user_nicename ) ); 718 719 $this->assertInstanceOf( 'WP_User', get_queried_object() ); 720 $this->assertSame( get_queried_object_id(), $user_id ); 721 } 699 722 }
Note: See TracChangeset
for help on using the changeset viewer.