Update: As of WordPress 3.0 you can use the built-in function get_page_by_title
with the third parameter $post_type
:
$post = get_page_by_title( 'Post Title', OBJECT, 'post_type' );
$post_id = $post ? $post->ID : 0;
Original Answer
you can use this function that jumps by google "get post by title"
/**
* Retrieve a post given its title.
*
* @uses $wpdb
*
* @param string $post_title Page title
* @param string $post_type post type ('post','page','any custom type')
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A.
* @return mixed
*/
function get_post_by_title($page_title, $post_type ='post' , $output = OBJECT) {
global $wpdb;
$post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type));
if ( $post )
return get_post($post, $output);
return null;
}
get_page_by_title
and is the custom post type hierarchal, i don't thinkget_page
(called byget_page_by_title
) will work for non-hierarchal types.get_page_by_title
?