WP_Query::is_post_type_archive() WordPress Method

The WP_Query::is_post_type_archive() method is used to check if the query is for a post type archive page.

WP_Query::is_post_type_archive( string|string[] $post_types = '' ) #

Is the query for an existing post type archive page?


Parameters

$post_types

(string|string[])(Optional) Post type or array of posts types to check against.

Default value: ''


Top ↑

Return

(bool) Whether the query is for an existing post type archive page.


Top ↑

Source

File: wp-includes/class-wp-query.php

	public function is_post_type_archive( $post_types = '' ) {
		if ( empty( $post_types ) || ! $this->is_post_type_archive ) {
			return (bool) $this->is_post_type_archive;
		}

		$post_type = $this->get( 'post_type' );
		if ( is_array( $post_type ) ) {
			$post_type = reset( $post_type );
		}
		$post_type_object = get_post_type_object( $post_type );

		return in_array( $post_type_object->name, (array) $post_types, true );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More