Wordpress 3.0
我希望通过使用帖子将特定帖子的内容放入页面中title.据我所知,我不能直接用它get_post().
我可以假设蛮力的方式可能是什么,但我怀疑有更优雅的方式?
<!--1.Get post ID by post title if you know the title or the title variable-->
<?php
$posttitle = 'post_title';
$postid = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_title = '" . $posttitle . "'" );
echo $postid;
?>
<!--2.use get_post($post_id) to get whatever you want to echo-->
<?php
$getpost= get_post($postid);
$postcontent= $getpost->post_content;
echo $postcontent;
?>
Run Code Online (Sandbox Code Playgroud)