Daniel Daniel - 6 months ago 10
PHP Question

WP: How to get the id of certain post by title

I would like to get the id of a post by title.

The script below shows the content of a post by id.

$content_post = get_post($postID);
$content = $content_post->post_content;

return apply_filters('the_content', $content);


My goal is to use the title as parameter in order to get the related id.

Answer

Can you please check this code?

$page = get_page_by_title(' Your page title '); // enter your page title

$pageID = $page->ID; 

echo $pageID;

for more information you can refer this link get_page_by_title ?