On this page
WP_Query::is_page( int|string|int[]|string[] $page = '' ): bool
Is the query for an existing single page?
Description
If the $page parameter is specified, this function will additionally check if the query is for one of the pages specified.
See also
Parameters
$pageint|string|int[]|string[] Optional-
Page ID, title, slug, path, or array of such to check against.
Default:
''
Return
bool Whether the query is for an existing single page.
Source
File: wp-includes/class-wp-query.php. View all references
public function is_page( $page = '' ) {
if ( ! $this->is_page ) {
return false;
}
if ( empty( $page ) ) {
return true;
}
$page_obj = $this->get_queried_object();
if ( ! $page_obj ) {
return false;
}
$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;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Query::get_queried_object() wp-includes/class-wp-query.php | Retrieves the currently queried object. |
| get_page_by_path() wp-includes/post.php | Retrieves a page given its path. |
Used By
| Used By | Description |
|---|---|
| WP_Query::generate_postdata() wp-includes/class-wp-query.php | Generate post data. |
| WP_Query::is_privacy_policy() wp-includes/class-wp-query.php | Is the query for the Privacy Policy page? |
| WP::register_globals() wp-includes/class-wp.php | Set up the WordPress Globals. |
| WP_Query::is_front_page() wp-includes/class-wp-query.php | Is the query for the front page of the site? |
| is_page() wp-includes/query.php | Determines whether the query is for an existing single page. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_query/is_page