WordPress | Function get page by title

WordPress | Function get_page_by_title() retrieves a post given its title. If more than one post uses the same title, the post with the smallest ID will be returned.

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

Syntax

Parameters

$page_title
(string) (required) Page title

Default: None
$output
(string) (optional) Output type. OBJECTARRAY_N, or ARRAY_A.

Default: OBJECT
$post_type
(string) (optional) Post type.

Default: page

Return Values

(mixed) 
OBJECTARRAY_N, or ARRAY_A. NULL when no posts found.

Source

File: wp-includes/post.php

get_page_by_title Function WordPress Developer Resources

Examples 1: Find Page ID to use with exclude in wp_list_pages

Examples 2: How To Find WordPress Page ID By Title Then Replace the_content()

Examples 2:  How to Find WordPress Custom Post Type by Title

Refference: https://codex.wordpress.org/Function_Reference/get_page_by_title

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.