how to get post data from post id in wordpress

We can fetch post data from wordpress database by using wordpress function

get_post ( int|WP_Post|null $post = null, string $output = OBJECT, string $filter = 'raw' )

// get post title name by post id
$post_7 = get_post( 7 );
$title = $post_7->post_title;

// Get post data by using post id
$post = get_post( 42 );
$output = apply_filters( 'the_content', $post->post_content );

// Array of get_post function contain there fields

WP_Post Object
(
[ID] =>
[post_author] =>
[post_date] =>
[post_date_gmt] =>
[post_content] =>
[post_title] =>
[post_excerpt] =>
[post_status] =>
[comment_status] =>
[ping_status] =>
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] =>
[post_modified_gmt] =>
[post_content_filtered] =>
[post_parent] =>
[guid] =>
[menu_order] =>
[post_type] =>
[post_mime_type] =>
[comment_count] =>
[filter] =>
)

Leave a Reply