Get post content by ID

How can I get a post’s content by post id? I tried get_page('ID'); to show content but it does not work.

Solutions Collecting From Web of "Get post content by ID"

You can do it multiple ways. Following are best two ways.

$post_id = 5// example post id
$post_content = get_post($post_id);
$content = $post_content->post_content;
echo do_shortcode( $content );//executing shortcodes

Another method

$content = get_post_field('post_content', $post_id);
echo do_shortcode( $content );//executing shortcodes

After Pieter Goosen suggestion on apply_filters.

You can use apply_filters if you wanted the content to be filtered by other plugins. So this eliminates the need to use do_shortcode


$post_id = 5// example post id
$post_content = get_post($post_id);
$content = $post_content->post_content;
echo apply_filters('the_content',$content);
 //no need to use do_shortcode, but content might be filtered by other plugins.

If you don’t want to allow other plugins to filter this content and need shortcode function then go with do_shortcode.

If you don’t want shortcode too then just play with the post_content.

I’ll just leave here another hacky ugly way that you may find useful sometimes. Of course methods which use API calls are always preferred (get_post(), get_the_content(), …).

global $wpdb;
$post_id = 123; // fill in your desired post ID
$post_content_raw = $wpdb->get_var(
        "select post_content from $wpdb->posts where ID = %d",

By using get_page('ID').

$page_id = 123;  //Page ID
$page_data = get_page($page_id); 
$title = $page_data->post_title; 
$content = $page_data->post_content;