In WordPress, we can get the content of the post ID by custom WordPress function. For that, add the following code in the template file and function in the theme folder.

1. Add the following code in the template file where the post content is to be displayed.

$postID = 12
echo get_post_content_by_id($postID);

Here $postID is the iD of the post, of which the content is to be displayed.

2. Add the following function definition in the function.php file in the theme folder.

function get_post_content_by_id($postID) {
$content_post = get_post($postID);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}

This function will return the content of the corresponding post id.

Categorized in:

Wordpress,