WP_Query::is_page() – Is the query for an existing single page?

You appear to be a bot. Output may be restricted

Description

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.

Usage

$bool = WP_Query::is_page( $page );

Parameters

$page
( int|string|int[]|string[] ) optional – Optional. Page ID, title, slug, path, or array of such to check against. Default empty.

Returns

bool Whether the query is for an existing single page.

Source

File name: wordpress/wp-includes/class-wp-query.php
Lines:

1 to 37 of 37
  public function is_page( $page = '' ) {
    if ( ! $this->WP_Query::is_page ) {
      return false;
    }

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

    $page_obj = $this->WP_Query::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;
  }
 

 View on GitHub View on Trac