您可以用做
$content_post = get_posts(array('name' => 'yourpostname')); // i.e. hello-world
if(count($content_post))
{
$content = $content_post[0]->post_content;
// do whatever you want
echo $content;
}
更新:你也可以在你的functions.php
添加此功能,可以從任何地方
function get_post_by_name($post_name, $post_type = 'post', $output = OBJECT) {
global $wpdb;
$post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s", $post_name, $post_type));
if ($post) return get_post($post, $output);
return null;
}
// call the function "get_post_by_name"
$content_post = get_post_by_name('hello-world');
if($content_post)
{
$content = $content_post->post_content;
// do whatever you want
echo $content;
}
更新叫它:爲了得到一個職位由它的標題你可以使用
// 'Hello World!' is post title here
$content_post = get_page_by_title('Hello World!', OBJECT, 'post');
,或者你可以用你的$item->item_title
變量
$content_post = get_page_by_title($item->item_title, OBJECT, 'post');
if($content_post)
{
$content = $content_post->post_content;
// do whatever you want
echo $content;
}
它的工作原理,如果我手動將崗位名稱。但是,如果我希望它是動態的<?php echo($ item-> item_title); ?>。我的意思是,我不知道PHP我問你要在'yourpostname'裏面放什麼,如果我想把itemtitle作爲postname ... – 2013-02-20 20:59:48
'post-name'是post'slug'在這裏,它不是標題,但是如果你想使用標題,那麼你可以使用[get_page_by_title](http://codex.wordpress.org/Function_Reference/get_page_by_title)。 – 2013-02-20 21:04:56
非常感謝!偉大的工程,你救了我:) – 2013-02-20 23:35:09