HOME > WordPress> 関数

$post->post_content id指定してコンテンツを取得

idが分かる場合は、
get_post(28)->post_content で直接取得する。
このままだと、改行が反映されず、nl2br()関数を使っても、うまく表示出来ない。

the_contentフィルターを適用することで、the_content関数と同様の出力結果になる。

$post_id = 1;
$post = get_post($post_id);
echo apply_filters('the_content',$post->post_content);