We all knew that there are WordPress functions that we can use to easily get post data by supplying just the post id as parameter like get_the_title($post->ID), get_permalink($post->ID), and get_the_date(‘format’, $post->ID). But did you notice that there is no such function to get the post content? There is a function get_the_content() but it doesn’t accept post id parameter.

Today, we will create a simple function to get the post content by just supplying the post id as parameter. Let’s use the get_post() function which accept post id parameter and return the post object. After getting the post content data from the post object, we will apply a filter to get the exact output as what the_content() function would normally return.

The function

Paste the code below into your theme’s functions.php.

function get_post_content($post_ID) {
	$get_post = get_post($post_ID);
	$post_content = $get_post->post_content;
	$post_content = apply_filters('the_content', $post_content);
	$post_content = str_replace(']]>', ']]>', $post_content);

	return $post_content;
}

How to use?

To use the code, simply call the function supplied with the post id as parameter

<?php echo get_post_content(12); ?>