WP_Query::is_page() public WP 3.1.0
Is the query for an existing single page?
If the $page parameter is specified, this function will additionally check if the query is for one of the pages specified.
{} It's a method of the class: WP_Query{}
No Hooks.
Return
true/false. Whether the query is for an existing single page.
Usage
global $wp_query; $wp_query->is_page( $page );
- $page(int/string/int[]/string[])
- Page ID, title, slug, path, or array of such to check against.
Default: ''
Notes
- See: WP_Query::is_single()
- See: WP_Query::is_singular()
Changelog
Since 3.1.0 | Introduced. |
Code of WP_Query::is_page() WP Query::is page WP 5.6
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, true ) ) {
return true;
} elseif ( in_array( $page_obj->post_title, $page, true ) ) {
return true;
} elseif ( in_array( $page_obj->post_name, $page, true ) ) {
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;
}