get_page_by_title( string$page_title, string$output=OBJECT, string|array$post_type="page")

Retrieve a page given its title.

You are watching: Get_page_by_title

Description #Description

If more than one write-up uses the exact same title, the short article with the smallest ID will be returned. It is in careful: in case of more than one short article having the exact same title, it will examine the oldest publication date, not the the smallest ID.

Because this duty uses the MySQL ‘=’ comparison, $page_title will normally be matched together case-insensitive with default collation.

Top ↑

Parameters #Parameters


(string)(Required)Page title.


(string)(Optional) The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Post object, an associative array, or a numeric array, respectively.

Default value: OBJECT


(string|array)(Optional) Post kind or variety of post types.

Default value: "page"

Top ↑

Return #Return

(WP_Post|array|null) WP_Post (or array) top top success, or null top top failure.

Top ↑

Source #Source

File: wp-includes/post.php

function get_page_by_title( $page_title, $output = OBJECT, $post_type = "page" ) global $wpdb;if ( is_array( $post_type ) ) $post_type = esc_sql( $post_type );$post_type_in_string = """ . Implode( "","", $post_type ) . """;$sql = $wpdb->prepare("SELECT IDFROM $wpdb->postsWHERE post_title = %sAND post_type IN ($post_type_in_string)",$page_title); rather $sql = $wpdb->prepare("SELECT IDFROM $wpdb->postsWHERE post_title = %sAND post_type = %s",$page_title,$post_type);$page = $wpdb->get_var( $sql );if ( $page ) return get_post( $page, $output );
Expand full source codeCollapse full source codeView ~ above TracView ~ above GitHub

Top ↑

Related #Related

Top ↑

Uses #Uses


Escapes data for usage in a MySQL query.


Retrieves write-up data given a short article ID or post object.


Retrieves one variable from the database.


Prepares a SQL query for safe execution.

Top ↑

Changelog #Changelog

3.0.0The $post_type parameter was added.

Top ↑

User added Notes #User added Notes

Skip to note 2 content
You have to log in to vote on the helpfulness that this noteVote outcomes for this note: 2You must log in to vote on the helpfulness of this note
Contributed by alordiel—2 year ago

It is very important to point out that the role will disregard any type of post_status so if it finds and also old write-up that is draft, that will show that result. For this reason if you have to filter by post status you better build your own query.

Top ↑

Feedback #FeedbackLog in to include feedback

You should log in prior to being maybe to contribute a note or feedback.

Code is Poetry.

Insert/edit linkClose

Enter the destination URL

Link Text
Open attach in a new tab

Or link to present content

No search term specified. Showing recent items.

See more: Jrr Tolkien Vs George Rr Martin Lyrics, Jrr Tolkien Vs George Rr Martin

Search or usage up and down arrowhead keys to choose an item.