wordpress get post body

WordPress: Get Post Body

  1. Get the Post ID: First, retrieve the ID of the post for which you want to get the body content.

  2. Retrieve the Post Object: Use the get_post() function to retrieve the post object using the post ID obtained in the previous step.

  3. Access the Post Body: Once you have the post object, you can access the post body content using the post_content property of the post object.

  4. Display or Use the Post Body: You can then display or use the post body content as needed in your WordPress theme or plugin.

// Step 1: Get the Post ID
$post_id = 123; // Replace 123 with the actual post ID

// Step 2: Retrieve the Post Object
$post = get_post($post_id);

// Step 3: Access the Post Body
if ($post) {
    $post_body = $post->post_content;
    // Step 4: Display or Use the Post Body
    echo $post_body; // Display the post body content
}