あなたはそれを使用してそれを行うことができます
$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;
}