How to get post by title in WordPress
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.