WP_Query::is_page( int|string|array $page = '' )

Is the query for an existing single page?


Description Description

If the $page parameter is specified, this function will additionally check if the query is for one of the pages specified.

See also See also


Top ↑

Parameters Parameters

$page

(int|string|array) (Optional) Page ID, title, slug, path, or array of such.

Default value: ''


Top ↑

Return Return

(bool) Whether the query is for an existing single page.


Top ↑

Source Source

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

	public function is_page( $page = '' ) {
		if ( ! $this->is_page ) {
			return false;
		}

		if ( empty( $page ) ) {
			return true;
		}

		$page_obj = $this->get_queried_object();

		$page = array_map( 'strval', (array) $page );

		if ( in_array( (string) $page_obj->ID, $page ) ) {
			return true;
		} elseif ( in_array( $page_obj->post_title, $page ) ) {
			return true;
		} elseif ( in_array( $page_obj->post_name, $page ) ) {
			return true;
		} else {
			foreach ( $page as $pagepath ) {
				if ( ! strpos( $pagepath, '/' ) ) {
					continue;
				}
				$pagepath_obj = get_page_by_path( $pagepath );

				if ( $pagepath_obj && ( $pagepath_obj->ID == $page_obj->ID ) ) {
					return true;
				}
			}
		}

		return false;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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