Get WordPress post by post id


    The most accurate answer

    Very simple
    $my_postid = 12;//This is page id or post id
    $content_post = get_post($my_postid);
    $content = $content_post->post_content;
    $content = apply_filters(‘the_content’, $content);
    $content = str_replace(‘]]>’, ‘]]>’, $content);
    echo $content;

    Bainternet's answer

    Short for the specific field: $ content = get_post_field ('post_content', $ my_postid); -  Rarst

    Get WordPress post by post id
    Lấy nội dung WordPress post bằng post id
    @Bainternet I'm just curious a bit here  $content = str_replace(‘]]>’, ‘]]>’, $content); What is the task here? -  Average Joe
    @AverageJoe It is looking and replacing the basics. When using the_content() the content is filtered. Because in the above example, the content was taken directly, and for safer he was using search and replace. -  Harish Chouhan
    Perhaps you also need do_shortcode() giống như $content = do_shortcode(get_post_field(‘post_content’, $my_postid)); – cyptus
    Is there a way to protect more_link? -  user2128576

    echo get_post_field(‘post_content’, $post_id);

    The answer of realmag777

    It would be better to do like this echo apply_filters(‘the_content’, get_post_field(‘post_content’, $post_id)); Ví dụ khi sử dụng qTranslate, giải pháp của bạn sẽ không đủ. – Karel Attl
    For example, when using qTranslate, your solution will not suffice. -  Karel Attl
    This is the best answer in case of post content when it is in the edit page of WordPress. -  mcont
    Without @KarelAttl's code, the line breaks in empty places. With apply_filters code, everything works perfectly. -  Alexander Taubenkorb
    apply_filters is a good choice, but it's not true for my current purpose. There are two options that are good. -  KnightHawk
    There are two answers to this question already. I will contribute another way to get WordPress content post th) post id eo
    $content=apply_filters(‘the_content’, get_post_field(‘post_content’, $my_postid));
    In order for the answer to be finalized, I add here methods 01 and 02:
    Method 01 (same as bainternet 's  answer ):
    $content_post = get_post($my_postid);
    $content = $content_post->post_content;
    $content = apply_filters(‘the_content’, $content);
    $content = str_replace(‘]]>’, ‘]]>’, $content);
    Method 02 (same as realmag777 's  answer ):
    $content=get_post_field(‘post_content’, $my_postid);
    Method 03:
    $content=apply_filters(‘the_content’, get_post_field(‘post_content’, $my_postid));

    No comments