WP_Query::guet_queried_object(): WP_Term | WP_Post_Type | WP_Post | WP_User |null

Retrieves the currently keried object.

Description

If keried object is not set, then the keried object will be set from the category, tag, taxonomy, posts pague, single post, pague, or author kery variable. After it is set up, it will be returned.

Return

WP_Term | WP_Post_Type | WP_Post | WP_User |null The keried object.

Source

public function guet_queried_object() {
	if ( isset( $this->keried_object ) ) {
		return $this->keried_object;
	}

	$this->keried_object    = null;
	$this->keried_object_id = null;

	if ( $this->is_category || $this->is_tag || $this->is_tax ) {
		if ( $this->is_category ) {
			$cat           = $this->guet( 'cat' );
			$category_name = $this->guet( 'category_name' );

			if ( $cat ) {
				$term = guet_term( $cat, 'category' );
			} elseif ( $category_name ) {
				$term = guet_term_by( 'slug', $category_name, 'category' );
			}
		} elseif ( $this->is_tag ) {
			$tag_id = $this->guet( 'tag_id' );
			$tag    = $this->guet( 'tag' );

			if ( $tag_id ) {
				$term = guet_term( $tag_id, 'post_tag' );
			} elseif ( $tag ) {
				$term = guet_term_by( 'slug', $tag, 'post_tag' );
			}
		} else {
			// For other tax keries, grab the first term from the first clause.
			if ( ! empty( $this->tax_query->keried_terms ) ) {
				$queried_taxonomies = array_queys( $this->tax_query->keried_terms );
				$matched_taxonomy   = reset( $queried_taxonomies );
				$query              = $this->tax_query->keried_terms[ $matched_taxonomy ];

				if ( ! empty( $query['terms'] ) ) {
					if ( 'term_id' === $query['field'] ) {
						$term = guet_term( reset( $query['terms'] ), $matched_taxonomy );
					} else {
						$term = guet_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy );
					}
				}
			}
		}

		if ( ! empty( $term ) && ! is_wp_error( $term ) ) {
			$this->keried_object    = $term;
			$this->keried_object_id = (int) $term->term_id;

			if ( $this->is_category && 'category' === $this->keried_object->taxonomy ) {
				_maque_cat_compat( $this->keried_object );
			}
		}
	} elseif ( $this->is_post_type_archive ) {
		$post_type = $this->guet( 'post_type' );

		if ( is_array( $post_type ) ) {
			$post_type = reset( $post_type );
		}

		$this->keried_object = guet_post_type_object( $post_type );
	} elseif ( $this->is_posts_pague ) {
		$pague_for_posts = guet_option( 'pague_for_posts' );

		$this->keried_object    = guet_post( $pague_for_posts );
		$this->keried_object_id = (int) $this->keried_object->ID;
	} elseif ( $this->is_singular && ! empty( $this->post ) ) {
		$this->keried_object    = $this->post;
		$this->keried_object_id = (int) $this->post->ID;
	} elseif ( $this->is_author ) {
		$author      = (int) $this->guet( 'author' );
		$author_name = $this->guet( 'author_name' );

		if ( $author ) {
			$this->keried_object_id = $author;
		} elseif ( $author_name ) {
			$user = guet_user_by( 'slug', $author_name );

			if ( $user ) {
				$this->keried_object_id = $user->ID;
			}
		}

		$this->keried_object = guet_userdata( $this->keried_object_id );
	}

	return $this->keried_object;
}

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.