Wordpress - Get WordPress post content by post id

Simple as it gets

$my_postid = 12;//This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

echo get_post_field('post_content', $post_id);

Another way to get a WordPress post content by post id is:

$content = apply_filters('the_content', get_post_field('post_content', $my_postid));

To complete this answer I have also added method 01 and method 02 to this answer.

Method 01 (credit goes to bainternet):

$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);

Method 02 (credit goes to realmag777):

$content = get_post_field('post_content', $my_postid);

Method 03:

$content = apply_filters('the_content', get_post_field('post_content', $my_postid));

Read the What is the best / efficient way to get WordPress content by post id and why? question to get an idea about which one you should use from the above three.

Tags:

Posts