Title: get_page_by_title
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_page_by_title( string $page_title, string $output = OBJECT, string|array $post_type = 'page' ): 󠀁[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)󠁿|array|null

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#wp--skip-link--target)

This function has been deprecated since 6.2.0. Use WP_Query instead.

Retrieves a page given its title.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#description)󠁿

If more than one post uses the same title, the post with the smallest ID will be
returned.
Be careful: in case of more than one post having the same title, it will
check the oldest publication date, not the smallest ID.

Because this function uses the MySQL ‘=’ comparison, $page_title will usually be
matched as case-insensitive with default collation.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#parameters)󠁿

 `$page_title`stringrequired

Page title.

`$output`stringoptional

The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
a [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) object, 
an associative array, or a numeric array, respectively.

Default:`OBJECT`

`$post_type`string|arrayoptional

Post type or array of post types. Default `'page'`.

Default:`'page'`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#return)󠁿

 [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|array|null
[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) (or array)
on success, or null on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#source)󠁿

    ```php
    function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
    	_deprecated_function( __FUNCTION__, '6.2.0', 'WP_Query' );
    	global $wpdb;

    	if ( is_array( $post_type ) ) {
    		$post_type           = esc_sql( $post_type );
    		$post_type_in_string = "'" . implode( "','", $post_type ) . "'";
    		$sql                 = $wpdb->prepare(
    			"SELECT ID
    			FROM $wpdb->posts
    			WHERE post_title = %s
    			AND post_type IN ($post_type_in_string)",
    			$page_title
    		);
    	} else {
    		$sql = $wpdb->prepare(
    			"SELECT ID
    			FROM $wpdb->posts
    			WHERE post_title = %s
    			AND post_type = %s",
    			$page_title,
    			$post_type
    		);
    	}

    	$page = $wpdb->get_var( $sql );

    	if ( $page ) {
    		return get_post( $page, $output );
    	}

    	return null;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/deprecated.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/deprecated.php#L4573)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/deprecated.php#L4573-L4605)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#related)󠁿

| Uses | Description | 
| [esc_sql()](https://developer.wordpress.org/reference/functions/esc_sql/)`wp-includes/formatting.php` |

Escapes data for use in a MySQL query.

  | 
| [_deprecated_function()](https://developer.wordpress.org/reference/functions/_deprecated_function/)`wp-includes/functions.php` |

Marks a function as deprecated and inform when it has been used.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  | 
| [wpdb::get_var()](https://developer.wordpress.org/reference/classes/wpdb/get_var/)`wp-includes/class-wpdb.php` |

Retrieves one value from the database.

  | 
| [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/)`wp-includes/class-wpdb.php` |

Prepares a SQL query for safe execution.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.0/) | Deprecated. Use [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/). | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | The `$post_type` parameter was added. | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#comment-content-6419)
 2.    [Gabor Lippert](https://profiles.wordpress.org/lunule/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/get_page_by_title/#comment-6419)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-6419)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-6419)
 4.  **_Deprecated !!!_**
 5.  Here’s the link to the deprecation info article: [https://make.wordpress.org/core/2023/03/06/get_page_by_title-deprecated/](https://make.wordpress.org/core/2023/03/06/get_page_by_title-deprecated/)
 6.  In a nutshell:
 7.  Peter Wilson recommends the following alternative:
 8.      ```php
         $posts = get_posts(
             array(
                 'post_type'              => 'page',
                 'title'                  => 'Sample Page',
                 'post_status'            => 'all',
                 'numberposts'            => 1,
                 'update_post_term_cache' => false,
                 'update_post_meta_cache' => false,           
                 'orderby'                => 'post_date ID',
                 'order'                  => 'ASC',
             )
         );
     
         $page_got_by_title = null;
     
         if ( ! empty( $posts ) ) {
             $page_got_by_title = $posts[0];
         } 
         ```
     
 9.  Or, alternatively, you can use the `new WP_Query()` method as well.
 10.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%3Freplytocom%3D6419%23feedback-editor-6419)
 11.  [Skip to note 7 content](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#comment-content-519)
 12.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_page_by_title/#comment-519)
 13. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-519)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-519)
 14. **How To Find WordPress Page ID By Title Then Replace [the_content()](https://developer.wordpress.org/reference/functions/the_content/)**
 15. In this example, we find the page id of “Sample Page” then replace the page’s 
     [the_content()](https://developer.wordpress.org/reference/functions/the_content/)
     with “Hello World!”
 16.     ```php
         function my_content($content) {
         	$page = get_page_by_title( 'Sample Page' );
         	if ( is_page($page->ID) )
         		$content = "Hello World!";
         	return $content;
         }
         add_filter('the_content', 'my_content');
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%3Freplytocom%3D519%23feedback-editor-519)
 18.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#comment-content-3324)
 19.   [Akira Tachibana](https://profiles.wordpress.org/atachibana/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/get_page_by_title/#comment-3324)
 20. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-3324)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-3324)
 21. **How to Find WordPress Custom Post Type by Title**
 22. This is useful for Custom Post Types. Below, we find the $post array of a Custom
     Post Type “link” with a title of “World Peace Now”:
 23.     ```php
         $mypost = get_page_by_title('World Peace Now', OBJECT, 'link');
         print_r($mypost);
         ```
     
 24. This comment was copied from Codex.
 25.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%3Freplytocom%3D3324%23feedback-editor-3324)
 26.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#comment-content-3593)
 27.   [alordiel](https://profiles.wordpress.org/alordiel/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/get_page_by_title/#comment-3593)
 28. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-3593)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-3593)
 29. It is **very important** to mention that the function will disregard any post_status
     so if it finds and old post that is draft, it will show that result. So if you
     need to filter by post status you better build your own query.
 30.  * It also returns posts that are in trash.
      * [Amy](https://profiles.wordpress.org/germanpearls/) [6 years ago](https://developer.wordpress.org/reference/functions/get_page_by_title/#comment-4506)
 31.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%3Freplytocom%3D3593%23feedback-editor-3593)
 32.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/get_page_by_title/?output_format=md#comment-content-518)
 33.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_page_by_title/#comment-518)
 34. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-518)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%23comment-518)
 35. **Find Page ID to use with exclude in wp_list_pages**
 36. This example will return the $page object for the page titled “About”. Then the
     $page->ID element is used to exclude the About page when listing pages.
 37.     ```php
         <?php 
         $page = get_page_by_title( 'About' );
         wp_list_pages( 'exclude=' . $page->ID );
         ?>
         ```
     
 38.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F%3Freplytocom%3D518%23feedback-editor-518)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_page_by_title%2F)
before being able to contribute a note or feedback.