Wordpress - Get post content from outside the loop
You can use get_page()
to return the $post
object of a static page:
$page_id = 302;
$page_object = get_page( $page_id );
echo $page_object->post_content;
Edit
Similarly, you can use get_post()
to return the $post
object of a post:
$post_id = 302;
$post_object = get_post( $post_id );
echo $post_object->post_content;
to get the content of the post outside the loop you can write something like this
global $post;
$content = $post->post_content;
if ( !empty( $content ) ) :
echo $content;
endif;
If your content include shortcodes, you should use:
$post_id = 22;
$post_object = get_post( $post_id );
echo do_shortcode( $post_object->post_content );