WordPress getting post content by post ID


Hello fellas, In this article I’m gonna show you how to get post content using post ID in WordPress.

Sometimes showing post content is so painful when you use the_content filter and custom post types. For example, when you create a custom post type “hotel” and want to show available hotel rooms -which rooms is another custom post type- on post pages, absolutely you can’t use the_content() or get_the_content().

The Function

// Print post content by post id.
function the_content_by_id($post_id) {
echo apply_filters('the_content', get_post_field('post_content', $post_id));


// Get post content by post id.
function get_the_content_by_id($post_id) {
return apply_filters('the_content', get_post_field('post_content', $post_id));

About function

function simply return/print the post content. Before print/return, function adds filters to the content. After hours of headache, this function definitely helps me a lot.

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir