| 3985 | | if ( $cat ) { |
| 3986 | | $term = get_term( $cat, 'category' ); |
| 3987 | | } elseif ( $category_name ) { |
| 3988 | | $term = get_term_by( 'slug', $category_name, 'category' ); |
| 3989 | | } |
| 3990 | | } elseif ( $this->is_tag ) { |
| 3991 | | $tag_id = $this->get( 'tag_id' ); |
| 3992 | | $tag = $this->get( 'tag' ); |
| | 3982 | if ( $this->is_category ) { |
| | 3983 | $cat = $this->get( 'cat' ); |
| | 3984 | $category_name = $this->get( 'category_name' ); |
| 3994 | | if ( $tag_id ) { |
| 3995 | | $term = get_term( $tag_id, 'post_tag' ); |
| 3996 | | } elseif ( $tag ) { |
| 3997 | | $term = get_term_by( 'slug', $tag, 'post_tag' ); |
| 3998 | | } |
| 3999 | | } else { |
| 4000 | | // For other tax queries, grab the first term from the first clause. |
| 4001 | | if ( ! empty( $this->tax_query->queried_terms ) ) { |
| 4002 | | $queried_taxonomies = array_keys( $this->tax_query->queried_terms ); |
| 4003 | | $matched_taxonomy = reset( $queried_taxonomies ); |
| 4004 | | $query = $this->tax_query->queried_terms[ $matched_taxonomy ]; |
| | 3986 | if ( $cat ) { |
| | 3987 | $term = get_term( $cat, 'category' ); |
| | 3988 | } elseif ( $category_name ) { |
| | 3989 | $term = get_term_by( 'slug', $category_name, 'category' ); |
| | 3990 | } |
| 4006 | | if ( ! empty( $query['terms'] ) ) { |
| 4007 | | if ( 'term_id' === $query['field'] ) { |
| 4008 | | $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); |
| 4009 | | } else { |
| 4010 | | $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); |
| 4011 | | } |
| 4012 | | } |
| 4013 | | } |
| 4014 | | } |
| | 3992 | } elseif ( $this->is_tag ) { |
| | 3993 | $tag_id = $this->get( 'tag_id' ); |
| | 3994 | $tag = $this->get( 'tag' ); |
| 4020 | | if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) { |
| 4021 | | _make_cat_compat( $this->queried_object ); |
| 4022 | | } |
| 4023 | | } |
| 4024 | | } elseif ( $this->is_post_type_archive ) { |
| 4025 | | $post_type = $this->get( 'post_type' ); |
| | 4002 | } else { |
| | 4003 | // For other tax queries, grab the first term from the first clause. |
| | 4004 | if ( ! empty( $this->tax_query->queried_terms ) ) { |
| | 4005 | $queried_taxonomies = array_keys( $this->tax_query->queried_terms ); |
| | 4006 | $matched_taxonomy = reset( $queried_taxonomies ); |
| | 4007 | $query = $this->tax_query->queried_terms[ $matched_taxonomy ]; |
| 4035 | | $this->queried_object = get_post( $page_for_posts ); |
| 4036 | | $this->queried_object_id = (int) $this->queried_object->ID; |
| 4037 | | } elseif ( $this->is_singular && ! empty( $this->post ) ) { |
| 4038 | | $this->queried_object = $this->post; |
| 4039 | | $this->queried_object_id = (int) $this->post->ID; |
| 4040 | | } elseif ( $this->is_author ) { |
| 4041 | | $author = (int) $this->get( 'author' ); |
| 4042 | | $author_name = $this->get( 'author_name' ); |
| | 4023 | if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) { |
| | 4024 | _make_cat_compat( $this->queried_object ); |
| | 4025 | } |
| | 4026 | } |
| 4057 | | return $this->queried_object; |
| | 4037 | } elseif ( $this->is_posts_page ) { |
| | 4038 | |
| | 4039 | $page_for_posts = get_option( 'page_for_posts' ); |
| | 4040 | |
| | 4041 | $this->queried_object = get_post( $page_for_posts ); |
| | 4042 | $this->queried_object_id = (int) $this->queried_object->ID; |
| | 4043 | |
| | 4044 | } elseif ( $this->is_singular && ! empty( $this->post ) ) { |
| | 4045 | |
| | 4046 | $this->queried_object = $this->post; |
| | 4047 | $this->queried_object_id = (int) $this->post->ID; |
| | 4048 | |
| | 4049 | } elseif ( $this->is_author ) { |
| | 4050 | |
| | 4051 | $author = (int) $this->get( 'author' ); |
| | 4052 | $author_name = $this->get( 'author_name' ); |
| | 4053 | |
| | 4054 | if ( $author ) { |
| | 4055 | $this->queried_object_id = $author; |
| | 4056 | } elseif ( $author_name ) { |
| | 4057 | $user = get_user_by( 'slug', $author_name ); |
| | 4058 | if ( $user ) { |
| | 4059 | $this->queried_object_id = $user->ID; |
| | 4060 | } |
| | 4061 | } |
| | 4062 | |
| | 4063 | $this->queried_object = get_userdata( $this->queried_object_id ); |
| | 4064 | } |
| | 4065 | |
| | 4066 | /** |
| | 4067 | * ---------------------------------------------------------- |
| | 4068 | * FIX 1: Homepage = "Your latest posts" → return post object |
| | 4069 | * ---------------------------------------------------------- |
| | 4070 | */ |
| | 4071 | if ( $this->is_home && ! $this->is_posts_page && null === $this->queried_object ) { |
| | 4072 | $this->queried_object = get_post_type_object( 'post' ); |
| | 4073 | return $this->queried_object; |
| | 4074 | } |
| | 4075 | |
| | 4076 | /** |
| | 4077 | * ---------------------------------------------------------- |
| | 4078 | * FIX 2: Date archives → return date object instead of null |
| | 4079 | * ---------------------------------------------------------- |
| | 4080 | */ |
| | 4081 | if ( $this->is_date && null === $this->queried_object ) { |
| | 4082 | $date_obj = new stdClass(); |
| | 4083 | $date_obj->year = get_query_var( 'year' ); |
| | 4084 | $date_obj->monthnum = get_query_var( 'monthnum' ); |
| | 4085 | $date_obj->day = get_query_var( 'day' ); |
| | 4086 | |
| | 4087 | $this->queried_object = $date_obj; |
| | 4088 | return $this->queried_object; |
| | 4089 | } |
| | 4090 | |
| | 4091 | return $this->queried_object; |