wordpress Get post ID by post title飞龙修订于 20070616 02:46 92 次浏览
Feilong want to get post id by title,but there is none template tags (get_post_by_title)directly to realize it. If you know a post id ,you can get the post title or content or slug very easily by using get_post($post_id).Still,if you want to Get page ID by title,you can use get_page_by_title.
BUT if you want to get the post id by title?When you have get or know the post title,how to get the post id?Here feilong code below for you to test in sidebar.php of your template.This post's modified url is http://feilong.org/wordpress-get-post-id-by-post-title
Firstly Get post ID by post title through querying the wordpress database,then you can use get_post($post_id) to get whatever you want to echo.
<!--1.Get post ID by post title if you know the title or the title variable-->
$posttitle = 'Hello world!';
$postid = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_title = '" . $posttitle . "'" );