Get Post title and content by using post ID – WordPress
Here is a code snippet for getting WordPress post title and content using script. Example uses post ID.
$my_id = 7; $post_id_7 = get_post($my_id); $title = $post_id_7->post_title; $content = $title = $post_id_7->post_content;
You must ONLY pass the variable containing an integer value and not the actual integer. The function receives value by reference.
$post_id is an array object:
Learn more here