get-post-by-title-in-wordpress

How to get post by title in WordPress

  • July 4, 2022

Here is the snippet to get post by title in wordpress

function get_post_by_title($page_title, $output = OBJECT) {
    global $wpdb;
    $post = $wpdb->get_var( 
    	$wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title )
    	);
    if ( $post ){
    	return get_post($post, $output);
    }
    return null;
}

If you want to get the custom post by title in wordpress just change post_type to your custom post type.

Related Post

bb-theme-wordpress

BB Theme WordPress: A Comprehensive Review and Guide

Welcome to the world of BB Theme WordPress Are you searching for the perfect WordPress theme to bring your website to life? Look no further! BB WordPress Theme is here to help you design a […]

How-To-Delete-A-WordPress

How to Delete a Theme in WordPress: A Step-by-Step Guide

Easy Ways to Delete Any Theme in WordPress Do you want to remove a WordPress theme and are looking for guidance on how to do it? Removing a theme can help declutter your site and […]

Salient-WP

Salient WordPress Theme: A Comprehensive Guide for Beginners

If you’re looking for a WordPress theme that combines versatility, functionality, and style, the salient wordpress theme is worth considering. salient wordpress theme is a multi-purpose WordPress theme that caters to various niches, including business, […]